After upload a file in Android Firebase Storage how get the file download Url? getDownloadUrl() not working

前端 未结 6 1801
無奈伤痛
無奈伤痛 2020-12-01 14:21

In my new android firebase project, I used com.google.firebase:firebase-storage:16.0.1 library.

I get the following Error:

I opened ano

6条回答
  •  执念已碎
    2020-12-01 14:51

    taskSnapshot.getDownloadUrl() is deprecated so i recommend that in your addOnSuccessListener() method, you use your storageReference and call the getDownloadUrl() method in order to get the url of the file and you can do whatever you want with it. Hope it helps.

             mUploadTask = storageRef.putFile(file).addOnSuccessListener(new OnSuccessListener() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    
                    // get the image Url of the file uploaded
                    storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {
                        @Override
                        public void onSuccess(Uri uri) {
                            // getting image uri and converting into string
                            Uri downloadUrl = uri;
                           fileUrl = downloadUrl.toString();
    
    
                        }
                    });
    
                }
            });
    

提交回复
热议问题