Firebase Storage的getDownloadUrl()方法无法解析 [英] Firebase Storage getDownloadUrl() method can't be resolved

查看:74
本文介绍了Firebase Storage的getDownloadUrl()方法无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要将图像上传到 Firebase存储,我将addOnSuccessListener附加到 StorageReference 的实例上.覆盖onSuccess方法时,我在taskSnapshot实例上调用getDownloadUrl(),但这给我一个错误,提示

To upload images to Firebase Storage I am attaching addOnSuccessListener on the instance of the StorageReference. While overriding onSuccess method I am calling getDownloadUrl() on the instance of taskSnapshot but it is giving me an error saying

无法解析方法getDownloadUrl()

Can't resolve method getDownloadUrl()

这个我在2个月前创建的应用程序,早些时候该应用程序运行良好,getDownloadUrl()也运行良好.另外,在taskSnapshot实例中,当我按 Ctrl + space 时,在建议中我找不到getDownloadUrl()方法.为什么会发生?

This app I had created 2 months ago, earlier this app was working fine and getDownloadUrl() was working fine as well. Also, in taskSnapshot instance when I press Ctrl+space, in the suggestions I don't find getDownloadUrl() method. Why is it happening?

onActivityResult()的代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Signed in!!!1", Toast.LENGTH_SHORT).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Failed to sign in", Toast.LENGTH_SHORT).show();
            finish();
        }
    }
    else if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
        Uri selectedPhoto = data.getData();

        StorageReference localRefrence = storageReference.child(selectedPhoto.getLastPathSegment());

        //  Uploading the file on the storage
        localRefrence.putFile(selectedPhoto).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                 Uri downloadUrl = taskSnapshot.getDownloadUrl();

                FriendlyMessage message = new FriendlyMessage(mUsername, null, downloadUrl.toString());
                databaseReference.push().setValue(message);
            }
        });
    }
}

推荐答案

Firebase API具有更改.

The Firebase API has changed.

2018年5月23日

May 23, 2018

云存储版本16.0.1

Cloud Storage version 16.0.1

删除了不推荐使用的StorageMetadata.getDownloadUrl()和UploadTask.TaskSnapshot.getDownloadUrl()方法.要获取当前的下载URL,请使用StorageReference.getDownloadUr().

Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().

UploadTask.TaskSnapshot 具有一种名为> ,它返回一个StorageMetadata对象.

UploadTask.TaskSnapshot has a method named getMetadata() which returns a StorageMetadata object.

StorageMetadata 对象包含一种名为 getReference() ,它返回一个StorageReference对象.

StorageReference 对象包含 getDownloadUrl() 方法,现在返回Task对象而不是Uri对象.

That StorageReference object contains the getDownloadUrl() method, which now returns a Task object instead of an Uri object.

然后必须侦听此Task以获得Uri,该Uri可以异步或以阻塞的方式完成;参见任务API .

This Task must then be listened upon in order to obtain the Uri, which can be done asynchronously or in a blocking manner; see the Tasks API for that.

这篇关于Firebase Storage的getDownloadUrl()方法无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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