Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get URI from storage reference on Firebase

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"

like image 634
bbenis Avatar asked May 21 '16 19:05

bbenis


People also ask

How do I get firebase storage URL?

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.

How do I get files from Firebase storage?

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.

What is storage reference in firebase?

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)

What is the firebase StorageReference object used for?

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.


1 Answers

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.

like image 179
Frank van Puffelen Avatar answered Sep 23 '22 21:09

Frank van Puffelen