Cannot resolve taskSnapshot.getDownloadUrl() in android firebase
Try this implementation. Use continueWithTask
to get the downloaded url.
final UploadTask uploadTask = filepath.putFile(uri);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
uploadTask.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();
}
// Continue with the task to get the download URL
return filepath.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
thumb_download_url = task.getResult().toString();
}
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
Cannot resolve getDownloadUrl() Firebase
Try to:
storageReference.child("YOUR_CHILD")
.putFile("FILE")
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
taskSnapshot
.getStorage()
.getDownloadUrl()
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Uri uri) {
//Put your result here
}
});
}
}
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.
Error: cannot find symbol Upload upload = new Upload(editTextName.getText().toString().trim(), taskSnapshot.getDownloadUrl().toString());
taskSnapshot.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
File file = new File(uri.getPath());
Upload upload = new Upload(editTextName.getText().toString().trim(), file.getPath());
}
});
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 aTask
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.
Related Topics
How to Create Custom Shape Button with Selector in Android
Canonical Registration Id and Message Id Format
I Want My Android Application to Be Only Run in Portrait Mode
Implicit "Submit" After Hitting Done on the Keyboard at the Last Edittext
Lame Mp3 Encoder Compile for Android
Android Mediaplayer/Videoview Error (1, -2147483648)
Android - Build Separate APKs for Different Processor Architectures
How to Find the Android Version Name Programmatically
Why Does Navigation Not Work in the Navigation Drawer Activity Template with Version 2.4.1
Multiple Table SQLite Db Adapter(S) in Android
Finding the Dominant Color of an Image in an Android @Drawable
How to Programmatically Log Out from Facebook Sdk 3.0 Without Using Facebook Login/Logout Button