Firebase Cloud Storage:权限被拒绝.检索downloadURL时无法执行此操作Firebase [英] Firebase Cloud Storage: permission denied. could not perform this operation firebase when retrieving downloadURL

查看:105
本文介绍了Firebase Cloud Storage:权限被拒绝.检索downloadURL时无法执行此操作Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项功能可以成功将图像上传到我的云存储桶.

I have a function that successfully uploads an image to my cloud storage bucket.

使用另一个功能,我想获取图像的URL以显示在我的页面上(使用<img.../>)

With another function I want to get the URL of the image to show it on my page (With <img.../>)

getImageUrl(id: string) {
    return this.storageRef.child('X/' + id ).getDownloadURL();

但是当我这样做时..我得到一个无效" URL,当我复制该URL并转到它时,得到以下消息:

But when I do this.. I get an 'invalid' URL and when I copy the URL and go to it, I get the following message:

{
  "error": {
    "code": 403,
    "message": "Permission denied. Could not perform this operation"
  }
}

我在某处读到这可能是因为URL中没有附加令牌,但是如何启用它呢?

I read somewhere that this might be because there is no token attached in the URL, but how can I enable this?

推荐答案

最近几天,我一直在试图了解Firebase Storage规则,但我不知道为什么,但是当我分开这样的写作和阅读规则时例如:

The last couple of days I have been trying to understand Firebase Storage rules and I don't know why but when I separate rules for writing and for reading like this for example:

allow write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;
allow read: if true;

该代码很好用,我可以使用getDownloadURL()进行读写,但是当我像这样一起使用它们时:

the code works great and I can write and read using getDownloadURL(), but when I use them together like this:

allow read, write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;

我和你有同样的错误:

{
  "error": {
  "code": 403,
  "message": "Permission denied. Could not perform this operation"
  }

}

将它们一起使用时我可以写,但是当我尝试使用getDownloadURL()读取文件时,就会出现问题.也许您可以尝试按我提到的方法将规则分开,看看它是否有效.我希望它能解决您的问题.另外,请不要忘记,自设置规则以来,规则在5分钟后生效 .祝你好运.

I can write when using them together, but when I try to read the file using getDownloadURL(), the issue appears. Maybe you could try separating the rules as I mention and see if it works. I hope it solves your problem. Also, don't forget that the rules are live after 5 minutes from the moment you set them. Good luck.

这篇关于Firebase Cloud Storage:权限被拒绝.检索downloadURL时无法执行此操作Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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