问题描述
Uri downloaduri=taskSnapshot.getDownloadUrl();//here i cant use getdownloadurl() function
DatabaseReference new_prod=db.push();
new_prod.child("product name").setValue(prod_name);
new_prod.child("product price").setValue(prod_price);
new_prod.child("available stock").setValue(prod_quan);
new_prod.child("product image").setValue(downloaduri);
pd.dismiss();//fragments code
我无法使用getdownloadurl.我已经将图像存储在Firebase存储器中了,这是限制使用getdownloadurl的片段吗?我的动机是要进行查询以存储在firebase中.请帮助我.
I was unable to use getdownloadurl .I have already stored image in the firebase storage.Is it the fragment that is restricting the use of getdownloadurl? My motive is to make a query to store in firebase.please help me.
推荐答案
在最新版本的Firebase Storage SDK中,已删除了taskSnapshot.getDownloadUrl()
方法.您需要立即从StorageReference
获取下载URL.
The taskSnapshot.getDownloadUrl()
method was removed in recent versions of the Firebase Storage SDK. You will need to instead get the download URL from the StorageReference
now.
调用StorageReference.getDownloadUrl()
会返回一个Task
,因为它需要从服务器检索下载URL.因此,您需要一个完成侦听器来获取实际的URL.
Calling StorageReference.getDownloadUrl()
returns a Task
, since it needs to retrieve the download URL from the server. So you'll need a completion listener to get the actual URL.
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png' in uri
System.out.println(uri.toString());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
或者,如果您在上传后立即获得下载网址(例如您的情况),则第一行可能是这样:
Alternatively that first line could be this if you're getting the download URL right after uploading (as in your case):
taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
另请参阅:
- Firebase Storage的getDownloadUrl()方法无法解决
- 错误:找不到符号com.google.firebase.storage.UploadTask.TaskSnapshot类型的getDownloadUrl()方法
- Firebase文档中上传文件并获取文件下载网址
- Firebase Storage getDownloadUrl() method can't be resolved
- Error: cannot find symbol method getDownloadUrl() of type com.google.firebase.storage.UploadTask.TaskSnapshot
- The example in the Firebase documentation on uploading a file and getting its download URL
这篇关于如何在最新版本中使用getdownloadurl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!