问题描述
Uri downloaduri=taskSnapshot.getDownloadUrl();//这里不能使用getdownloadurl()函数数据库参考 new_prod=db.push();new_prod.child("产品名称").setValue(prod_name);new_prod.child("产品价格").setValue(prod_price);new_prod.child("可用库存").setValue(prod_quan);new_prod.child("产品图片").setValue(downloaduri);pd.dismiss();//片段代码
我无法使用 getdownloadurl .我已经在 firebase 存储中存储了图像.是否是限制使用 getdownloadurl 的片段?我的动机是查询以存储在 firebase 中.请帮助我.
taskSnapshot.getDownloadUrl()
方法已在 Firebase Storage SDK 的最新版本中删除.您现在需要从 StorageReference
获取下载 URL.
调用 StorageReference.getDownloadUrl()
返回一个 Task
,因为它需要从服务器检索下载 URL.因此,您需要一个完成侦听器来获取实际 URL.
来自有关下载文件的文档:
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {@覆盖公共无效onSuccess(Uri uri){//得到 uri 中 'users/me/profile.png' 的下载 URLSystem.out.println(uri.toString());}}).addOnFailureListener(new OnFailureListener() {@覆盖public void onFailure(@NonNull 异常异常){//处理任何错误}});
或者,如果您在上传后立即获取下载 URL(如您的情况),则第一行可能是这样的:
taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {
另见:
- 无法解析 Firebase Storage getDownloadUrl() 方法
- 错误:找不到符号com.google.firebase.storage.UploadTask.TaskSnapshot 类型的 getDownloadUrl() 方法
- Firebase 文档中关于上传文件并获取它的示例下载地址
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
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.
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.
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.
From the documentation on downloading a file:
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>() {
Also see:
- 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!