2017-03-12 57 views
0

我尝试使用元数据在火力地堡存储意味着安全规则,它不工作:火力地堡储存安全规则不工作

service firebase.storage { 
    match <firebase-storage-url> { 
    match /{userId}/{allPaths=**}{ 
    allow read: if resource.metadata.userid== userId; 
    allow write: if resource.metadata.userid== userId 
    } 
    } 
} 


StorageMetadata metadata = new StorageMetadata.Builder() 
      .setCustomMetadata("userid", user.ID) 
      .build(); 

filepath = mStorage.child(user.ID + "/" + String.valueOf(chatmessageamount + 1) + ".mp3"); 

有人能帮助我吗?

+0

请说明您的具体问题或添加额外的细节,突显正是你需要的。正如目前所写,很难确切地说出你在问什么。请参阅如何问问页面以获取帮助以澄清此问题。 http://stackoverflow.com/help/how-to-ask –

+0

我想使用元数据的安全规则,并说明我是如何实现的,它不工作 –

+0

第一部分是存储安全规则。第二部分是我如何将文件上传到Firebase存储 –

回答

1

我想你想要的是:

service firebase.storage { 
    match /b/{bucket}/o { // this should be this string literally, no need to put in the bucket name 
    match /{userId}/{allPaths=**}{ 
     allow read: if request.auth.uid == userId; 
     allow write: if request.resource.metadata.userId == userId; // request.resource is the resource being written, resource is what already exists (which on first write will be null) 
    } 
    } 
} 
+0

我试着不工作。读取始终工作,不管限制 –

+0

我没有使用该行:match/b/{bucket}/o {也许这是读取始终工作的原因。使用水桶线而不是我的项目名称的重要性是什么? –

+2

规则匹配对象的RESTful路径(即'/ b/some-bucket/o/path/to/object'),'{bucket}'捕获任何bucket名称。没有这一点,规则应该失败,因为它们不应该匹配。请注意,如果您通过下载令牌下载,则会忽略这些规则。 –