I am developing android application where a user clicks image, it gets stored in firebase, cloud functions process this image and stores the output back in the firebase in the form of text file. In order to display the output in android, application keeps checking for output file if it exists or not. If yes, then it displays the output in the application. If no, I have to keep waiting for the file till it is available.
I'm unable to find any documentation for checking if any file is exists in Firebase or not. Any help or pointers will be helpful.
Thanks.
If you want the file path on firebase storage to access it via storage reference and not URL, you can use taskSnapshot. getStorage().
There is no way to list files, search for files or filter files within the Firebase Storage API. There are some such features in the gcloud API, which can also be used on Firebase Storage. This user is first on the weekly Google Cloud leaderboard.
From the navigation pane of the Firebase console, select Storage, then click Get started. Review the messaging about securing your Cloud Storage data using security rules. During development, consider setting up your rules for public access. Select a location for your default Cloud Storage bucket.
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:
storageRef.child("file.png").getDownloadURL().then(onResolve, onReject);
function onResolve(foundURL) {
//stuff
}
function onReject(error){
//fill not found
console.log(error.code);
}
Updated
This is another simpler and cleaner solution.
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
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With