and-nd-firebase
and-nd-firebase copied to clipboard
cannot resolve getDownloadUrl please help me out here is the code
public void createOrUpdateProfileWithImage(final Profile profile, Uri imageUri, final OnProfileCreatedListener onProfileCreatedListener) { String imageTitle = ImageUtil.generateImageTitle(UploadImagePrefix.PROFILE, profile.getId()); UploadTask uploadTask = databaseHelper.uploadImage(imageUri, imageTitle);
if (uploadTask != null) {
uploadTask.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Uri downloadUrl = task.getResult().getDownloadUrl(); //problem here
LogUtil.logDebug(TAG, "successful upload image, image url: " + String.valueOf(downloadUrl));
profile.setPhotoUrl(downloadUrl.toString());
createOrUpdateProfile(profile, onProfileCreatedListener);
} else {
onProfileCreatedListener.onProfileCreated(false);
LogUtil.logDebug(TAG, "fail to upload image");
}
});
somebody, please notice this.. hehe
+1
Hi! you can replace it with this according to the firebase documentation: `Uri selectedImageUri=data.getData();
final StorageReference photoRef=
mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).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 photoRef.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
FriendlyMessage friendlyMessage= new FriendlyMessage(null,mUsername,downloadUri.toString());
mMessagesDatabaseReference.push().setValue(friendlyMessage);
} else {
// Handle failures
// ...
}
}
});`
have you found the solution ?, help me please.