After Upload A File In Android Firebase Storage How Get The File Download Url? GetDownloadUrl() Not Working


Answer :

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());             }         });     } }); 

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.


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<UploadTask.TaskSnapshot>() {             @Override             public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {                  // get the image Url of the file uploaded                 storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {                     @Override                     public void onSuccess(Uri uri) {                         // getting image uri and converting into string                         Uri downloadUrl = uri;                        fileUrl = downloadUrl.toString();                       }                 });              }         }); 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable