如何在最新版本中使用getdownloadurl? [英] How to use getdownloadurl in recent versions?

查看:243
本文介绍了如何在最新版本中使用getdownloadurl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

                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() 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆