Tasksnapshot.Getdownloadurl() Is Deprecated

Replacing the deprecated taskSnapshot.getDownloadUrl().toString();

getDownloadUrl() is deprecated so you need to use Task and check isComplete() like below to see if it is completed

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICTURE_RESULT && resultCode == RESULT_OK) {
Uri imageUri = data.getData();
StorageReference ref = FirebaseUtil.mStorageRef.child(imageUri.getLastPathSegment());
ref.putFile(imageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
while(!uri.isComplete());
Uri url = uri.getResult();

Log.i(TAG, url.toString());
deal.setImageUrl(url.toString());

taskSnapshot.getDownloadUrl() method not working

Edit: see this comment on why the approach in this answer doesn't work:

firebaser here This answer is wrong. While it at first may appear to work (since it compiles) the result of getDownloadUrl().toString() is not a download URL, but a string representation of a Task object. For a better answer, see stackoverflow.com/a/55503926 or the sample in the Firebase documentation.

Original answer below...


In Firebase Storage API version 16.0.1,
the getDownloadUrl() method using taskSnapshot object has changed.
now you can use,

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()

to get download url from the firebase storage.

Firebase Storage getDownloadUrl() method can't be resolved

The Firebase API has changed.

May 23, 2018

Cloud Storage version 16.0.1

Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().

UploadTask.TaskSnapshot has a method named getMetadata() which returns a StorageMetadata object.

This StorageMetadata object contains a method named getReference() which returns a StorageReference object.

That StorageReference object contains the getDownloadUrl() method, which now returns a Task object instead of an Uri object.

This Task must then be listened upon in order to obtain the Uri, which can be done asynchronously or in a blocking manner; see the Tasks API for that.



Related Topics



Leave a reply



Submit