如何将Firebase存储规则部署到特定存储桶?

问题描述 投票:0回答:1

我想知道存储规则部署在Firebase中的工作原理。

在Firebase存储中,我有2个桶app.appspot.comapp-mybucket。在我的本地机器上,我有一个storage.rules文件,看起来像这样:

service firebase.storage {
  match /b/app.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
  match /b/app-mybucket/o {
    match /{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}

当我firebase deploy --only storage这些规则被发送到默认的app.appshpot.com桶,似乎没有任何东西被发送到app-mybucket。我想知道一种可以将规则部署到所有存储桶的方法。

firebase firebase-storage firebase-security-rules firebase-cli
1个回答
2
投票

在firebase.json文件中,您可以指定以下内容:

  "storage": [{
    "rules": "my-appspot.rules",
    "bucket": "app.appspot.com"
  },
  {
    "rules": "my-bucket.rules",
    "bucket": "app-mybucket"
  }]

上面的示例使用每个存储桶的不同规则,如果您愿意,也可以为每个存储桶使用相同的规则。

© www.soinside.com 2019 - 2024. All rights reserved.