Tasksnapshot.getdownloadurl() Method Not Working
Solution 1:
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.
Solution 2:
To get imageUrl path from storage use this code:
uploadTask.addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
@OverridepublicvoidonSuccess(UploadTask.TaskSnapshot taskSnapshot) {
if (taskSnapshot.getMetadata() != null) {
if (taskSnapshot.getMetadata().getReference() != null) {
Task<Uri> result = taskSnapshot.getStorage().getDownloadUrl();
result.addOnSuccessListener(newOnSuccessListener<Uri>() {
@OverridepublicvoidonSuccess(Uri uri) {
String imageUrl = uri.toString();
//createNewPost(imageUrl);
}
});
}
}
}});
that is all 😉
NOTE: Do not forget initialize StorageReference and UploadTask in your uploadFile method.
Solution 3:
Try Using this it will download the image from FireBase storage
FireBase Libraries versions 16.0.1
Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
result.addOnSuccessListener(newOnSuccessListener<Uri>() {
@OverridepublicvoidonSuccess(Uri uri) {
String photoStringLink = uri.toString();
}
});
Solution 4:
I faced the similar error I solved it with this method. Hope it helps
uploadTask.addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
@OverridepublicvoidonSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> task = taskSnapshot.getMetadata().getReference().getDownloadUrl();
task.addOnSuccessListener(newOnSuccessListener<Uri>() {
@OverridepublicvoidonSuccess(Uri uri) {
String photoLink = uri.toString();
Map userInfo = newHashMap();
userInfo.put("profileImageUrl", photoLink);
mUserDatabase.updateChildren(userInfo);
}
});
finish();
return;
}
});
Solution 5:
ref.putFile(filePath)
.addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>() {
@OverridepublicvoidonSuccess(UploadTask.TaskSnapshot taskSnapshot) {
taskSnapshot.getStorage().getDownloadUrl().addOnCompleteListener(newOnCompleteListener<Uri>() {
@OverridepublicvoidonComplete(@NonNull Task<Uri> task) {
changeProfilePic(String.valueOf(task.getResult()));//gives image or file string url
}
});
try this code will work for sure
Post a Comment for "Tasksnapshot.getdownloadurl() Method Not Working"