2017-03-12 7 views
0

を働いていない:Firebaseストレージセキュリティルールは、私は、メタデータを使用してFirebaseストレージ上のセキュリティルールを暗示しようとすると、それが機能していない

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

あなたの特定の問題を明確にしたり、必要な正確に何を強調表示するために、追加の詳細情報を追加してください。現在書かれているとおり、あなたが求めていることを正確に伝えるのは難しいです。この質問を明確にする方法については、How to Askページを参照してください。 http://stackoverflow.com/help/how-to-ask –

+0

私はセキュリティルールにメタデータを使用したいのですが、それをどのように実装し、それが動作しないのか –

+0

最初の部分はストレージセキュリティルールです。 2番目の部分はファイルを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

ルールはオブジェクト( '/ b/some-bucket/o/path/to/object')へのRESTfulパスと一致し、' {バケット} 'はバケット名を取得します。それがなければ、ルールは何も一致しないので失敗するはずです。ダウンロードトークンを使用してダウンロードする場合、ルールは無視されます。 –

関連する問題