private void uploadImageToFirebaseStorage() {
StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");
if (uriProfileImage != null) {
progressBar.setVisibility(View.VISIBLE);
profileImageRef.putFile(uriProfileImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressBar.setVisibility(View.GONE);
Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
taskSnapshot.getDownloadUrl()
方法不工作,下面有红线
最佳答案
编辑:参见this comment为什么这个答案中的方法不起作用:
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.
下面是原始答案...
在 Firebase Storage API
版本 16.0.1 中,
使用 taskSnapshot 对象的 getDownloadUrl() 方法已更改。
现在你可以使用了,
taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
从 firebase 存储中获取下载 url。
关于android - taskSnapshot.getDownloadUrl() 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585334/