bbenis
bbenis

Reputation: 535

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"

Upvotes: 9

Views: 10301

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599131

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.

Upvotes: 12

Related Questions