我正在开发 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/