Unable to get URI from storage reference on Firebase

余生颓废 提交于 2021-02-07 06:13:28

问题


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"


回答1:


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.



来源:https://stackoverflow.com/questions/37367137/unable-to-get-uri-from-storage-reference-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!