1
我有一个要求,我的应用程序将允许用户上传图片。在Firebase存储中是否有一项功能,可以在用户/某个其他用户尝试加载相同图像时防止重复并使用旧图像网址。有没有办法来防止重复图片上传到firebase存储
我有一个要求,我的应用程序将允许用户上传图片。在Firebase存储中是否有一项功能,可以在用户/某个其他用户尝试加载相同图像时防止重复并使用旧图像网址。有没有办法来防止重复图片上传到firebase存储
是的。散列图像并使用该名称存储文件。编写一个不允许覆盖文件的规则。
// 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
}
}
}