【问题标题】:Android Firebase - Remove uploaded image from StorageAndroid Firebase - 从存储中删除上传的图像
【发布时间】:2020-03-21 07:47:33
【问题描述】:

我正在开发一项功能来删除上传的文件。我目前可以删除 Cloud Firestore 中的引用,但无法从存储中删除它。下面的代码应该从存储中删除,但它不起作用

    private void deleteImage(String id, final int position, String fileUrl) {

    StorageReference storageRef = FirebaseStorage.getInstance().getReference("uploads");

    // Create a reference to the file to delete
    StorageReference fileRef = storageRef.child(fileUrl);

    // Delete the file
    fileRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            // File deleted successfully
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Uh-oh, an error occurred!
        }
    });
}

错误消息是“没有请求的身份验证令牌。发生了 StorageException。对象在该位置不存在。HttpResult:404”。我认为问题与我的 fileUrl 字段有关,但我不确定。 fileUrl 是下载图像的 url,例如,如果我将 url 复制并粘贴到网络浏览器上,我可以看到图像。为什么不工作?

【问题讨论】:

  • The fileUrl is the download image url, 那是一个提供html页面的url。看起来不适合作为文件参考。

标签: android firebase firebase-storage


【解决方案1】:

正如@blackapps 评论的那样,我使用的下载 url 不适合作为文件的引用,因此我将 fileUrl 参数的值更改为 "filename.file_extension"。代码还是一样,只是改了参数值。

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 2018-03-15
    • 2021-04-25
    • 2019-02-11
    • 2018-06-05
    相关资源
    最近更新 更多