Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

I get the following Error:

enter image description here

I opened another project that had library firebase-storage:15.0.2 and taskSnapshot.getDownloadUrl(); which worked on that project. but after using latest dependency library it's not working.

Now, how can I get the file URL?

Any way to get the file download link?

like image 355
Sheikh Hasib Avatar asked May 28 '18 17:05

Sheikh Hasib


People also ask

How can I get download URL from Firebase storage?

Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .

How can I get URL of uploaded image in Firebase storage?

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.


Video Answer


2 Answers

I had Found 2 solution for my issue.

Firebase Google Documentation :

//add file on Firebase and got Download Link filePath.putFile(imageUri).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {     @Override     public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {         if (!task.isSuccessful()){             throw task.getException();         }         return filePath.getDownloadUrl();     } }).addOnCompleteListener(new OnCompleteListener<Uri>() {     @Override     public void onComplete(@NonNull Task<Uri> task) {         if (task.isSuccessful()){             Uri downUri = task.getResult();             Log.d(TAG, "onComplete: Url: "+ downUri.toString());         }     } }); 

Another solution!

It's more easy and small than google Firebase documentation and I'll use it:

filePath.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {     @Override     public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {         filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {             @Override             public void onSuccess(Uri uri) {                 Log.d(TAG, "onSuccess: uri= "+ uri.toString());             }         });     } }); 
like image 161
Sheikh Hasib Avatar answered Nov 15 '22 15:11

Sheikh Hasib


That method has been deprecated on version 16.0.1 (check Firebase release notes) so you have to use

StorageReference.getDownloadUrl()

If you want to get them after uploading the file, then you must check their documentation here. It is already updated.

like image 26
goblin Avatar answered Nov 15 '22 13:11

goblin