When using the database you can do snapshot.exists()
to check if certain data exists. According to the docs there isn't a similar method with storage.
当使用数据库时,您可以做快照。存在()来检查是否存在某些数据。根据文档,没有类似的存储方法。
https://firebase.google.com/docs/reference/js/firebase.storage.Reference
https://firebase.google.com/docs/reference/js/firebase.storage.Reference
What is the proper way of checking if a certain file exists in Firebase Storage?
检查某个文件是否存在于Firebase存储中的正确方法是什么?
2 个解决方案
#1
4
I believe that the FB storage API is setup in a way that the user only request a file that exists.
我认为FB存储API的设置方式是用户只请求存在的文件。
Thus a non-existing file will have to be handled as an error: https://firebase.google.com/docs/storage/web/handle-errors
因此,一个不存在的文件必须作为一个错误处理:https://firebase.google.com/docs/storage/web/handle错误
#2
11
You can use getDownloadURL which returns a Promise, which can in turn be used to catch a "not found" error, or process the file if it exists. For example:
您可以使用getDownloadURL返回一个承诺,该承诺反过来可以用于捕获“未找到”错误,或者处理存在的文件。例如:
storageRef.child("file.png").getDownloadURL().then(onResolve, onReject);
function onResolve(foundURL) {
//stuff
}
function onReject(error) {
console.log(error.code);
}
#1
4
I believe that the FB storage API is setup in a way that the user only request a file that exists.
我认为FB存储API的设置方式是用户只请求存在的文件。
Thus a non-existing file will have to be handled as an error: https://firebase.google.com/docs/storage/web/handle-errors
因此,一个不存在的文件必须作为一个错误处理:https://firebase.google.com/docs/storage/web/handle错误
#2
11
You can use getDownloadURL which returns a Promise, which can in turn be used to catch a "not found" error, or process the file if it exists. For example:
您可以使用getDownloadURL返回一个承诺,该承诺反过来可以用于捕获“未找到”错误,或者处理存在的文件。例如:
storageRef.child("file.png").getDownloadURL().then(onResolve, onReject);
function onResolve(foundURL) {
//stuff
}
function onReject(error) {
console.log(error.code);
}