android - 如何从您的 Android 应用程序检查 Firebase 存储中是否存在文件?

标签 android firebase firebase-storage

我正在开发 android 应用程序,其中用户单击图像,它存储在 firebase 中,云函数处理此图像并将输出以文本文件的形式存储回 firebase。为了在 android 中显示输出,应用程序会不断检查输出文件是否存在。如果是,则它会在应用程序中显示输出。如果没有,我必须一直等待文件可用。

我找不到任何文档来检查 Firebase 中是否存在任何文件。任何帮助或指示都会有所帮助。

谢谢。

最佳答案

您可以使用返回 Promise 的 getDownloadURL,后者又可用于捕获“未找到”错误,或处理文件(如果存在)。例如:

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

function onResolve(foundURL) { 
//stuff 
} 
function onReject(error){ 
//fill not found
console.log(error.code); 
}

已更新

这是另一个更简单、更清洁的解决方案。

storageRef.child("users/me/file.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        // Got the download URL for 'users/me/profile.png'
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // File not found
    }
});

关于android - 如何从您的 Android 应用程序检查 Firebase 存储中是否存在文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43567626/

相关文章:

android - 打开并关闭youtube视频的Android应用

javascript - Firebase JavaScript : Callback function does not return anything

android - 如何摆脱 Android Studio 警告 "Result of getException() not thrown"?

android - Firestore/Firebase 无法从文件夹获取图像

android - taskSnapshot.getDownloadUrl() 方法不起作用

android - CATEGORY_INFO 在 Android 中有什么用?

android - 如何使用 new places sdk for android 查找附近的地方?

android - fragment 中的 RecyclerView 不工作(无法向其添加数据)

firebase - 如何限制组成员对文件的访问?

javascript - 如何读取/写入本地文件 :///HTML document? 的 cookie