gpt4 book ai didi

android - taskSnapshot.getDownloadUrl() 方法不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:29:53 24 4
gpt4 key购买 nike

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 a Task 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com