2017-04-08 38 views
1

私のアプリではユーザーが画像をアップロードできるようにする必要があります。 Firebaseストレージには、重複を防ぐことができ、ユーザー/他のユーザーが同じイメージを読み込もうとしているときに古いイメージURLを使用できる機能がありますか?イメージがファイアベースのストレージに重複してアップロードされないようにする方法はありますか?

答えて

-1

はい。イメージをハッシュし、その名前を使用してファイルを保存します。ファイルの上書きを許可しないルールを作成します。

// Upload the file on the client to a file named after a hash of the data 
var string = 'Hello, world!' 
firebase.storage().ref().child('images/' + hash(string)).putString(string); 

var hash = function(string) { /* SHA1, MD5, etc. (note: collisions exist for certain algorithms) */ } 


// Rules 
service firebase.storage { 
    match /b/{bucket}/o { 
    match /images/{imageHash} { 
     // only allow create and delete, not overwrite 
     allow write: if resource == null || request.resource == null 
    } 
    } 
} 
関連する問題