问题 如何检查Firebase存储中是否存在文件?


使用数据库时,您可以这样做 snapshot.exists() 检查是否存在某些数据。根据文档,没有类似的存储方法。

https://firebase.google.com/docs/reference/js/firebase.storage.Reference

检查Firebase存储中是否存在某个文件的正确方法是什么?


9246
2018-06-10 14:49


起源



答案:


我相信FB存储API的设置方式是用户只请求存在的文件。

因此,必须将不存在的文件作为错误处理: https://firebase.google.com/docs/storage/web/handle-errors


5
2018-06-10 16:17





您可以使用 getDownloadURL 返回一个 诺言,它可以反过来用于捕获“未找到”错误,或处理文件(如果存在)。例如:

storageRef.child("file.png").getDownloadURL().then(onResolve, onReject);

function onResolve(foundURL) {
    //stuff
}

function onReject(error) {
    console.log(error.code);
}

11
2018-06-10 16:21