尝试从Firebase存储加载图像时出现403禁止错误 [英] Getting 403 Forbidden error when trying to load image from Firebase Storage

查看:85
本文介绍了尝试从Firebase存储加载图像时出现403禁止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase存储为我的Android应用上的用户存储和加载图像.使用前必须对所有用户进行身份验证.有时,某些用户个人资料图像未显示并抛出"403 Forbidden"错误.这些图像以前显示过,我不确定为什么它们停止工作. 我在Firebase存储上使用以下规则:

I'm using firebase storage to store and load images for users on my android app. All users must be authenticated before using it. Occasionally, some user profile images are not showing and throwing "403 Forbidden" error. Those images were displaying before, I'm not sure why they stop working. i'm using the following rules on my firebase storage:

 service firebase.storage {
   match /b/<storage_address>.appspot.com/o {
    match /{allPaths=**} {
     allow read: if request.auth != null;
     allow write: if request.auth != null;
    }
  }
}

如果我将读取规则更改为allow read;,则所有图像均正常工作. 这是我的显示方法:

if i change the read rule to allow read; all the images are working properly. This is my display method:

Picasso.Builder builder = new Picasso.Builder(this);
                builder.listener(new Picasso.Listener()
                {
                    @Override
                    public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)
                    {
                        exception.printStackTrace();
                    }
                });
                builder.build().load(URL).into(imgView);

图片网址看起来像这样:

The image URL looks something like this:

https://firebasestorage.googleapis.com/v0/b/<storage_address>.appspot.com/o/images%2Fprofile%2Fphoto%2F36805?alt=media&token=e62ec151-3aaf-4e5c-aefb-1b3c93828684

这与令牌有关吗?

推荐答案

可能为时已晚,但可能对其他人有所帮助.我遇到了同样的问题,我的问题是Firebase存储中的文件名是唯一的.如果您上传具有相同文件名的新文件,它将覆盖旧文件并为其生成新令牌,从而使旧网址过时. 您应该为上传的文件生成一个唯一的文件名,然后将其修复.

Probably comes too late, but maybe helpful for someone else. I had the same issue, my problem is that filenames in firebase storage are unique. If you upload a new file with the same filename it will override the old one and generate a new token for it, making the old url obsolete. You should generate a unique filename for your uploaded file and then it should be fixed.

这篇关于尝试从Firebase存储加载图像时出现403禁止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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