I'm trying to get an image URI that is stored in Firebase storage, in order to process it using another method. I'm using the following:
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl(this.getString(R.string.storage_path));
Uri uri = storageRef.child("groups/pizza.png").getDownloadUrl().getResult();
and getting an error "java.lang.IllegalStateException: Task is not yet complete"
Image URL is obtained by uploading an image to firebase bucket and then that can return back a URL that URL is a permanent URL which can be open anywhere. Then a user can use this URL for any purpose in its application.
To download a file, first create a Cloud Storage reference to the file you want to download. You can create a reference by appending child paths to the root of your Cloud Storage bucket, or you can create a reference from an existing gs:// or https:// URL referencing an object in Cloud Storage.
public class StorageReference extends Object. implements Comparable<StorageReference> Represents a reference to a Google Cloud Storage object. Developers can upload and download objects, get/set object metadata, and delete an object at a specified path. ( see Google Cloud Storage)
StorageReference is a reference to a Google Cloud Storage object. It is possible to upload, download, and delete objects, as well as get or set the object metadata.
You can get the download URL for a file with:
storageRef.child("groups/pizza.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// TODO: handle uri
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
See the Firebase documentation for downloading data via a URL.
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