angular - Firebase Cloud Storage : permission denied. 在检索 downloadURL 时无法执行此操作 firebase

标签 angular firebase firebase-storage

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

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

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

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

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

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

最佳答案

最近几天我一直在尝试了解 Firebase 存储规则,但我不知道为什么,但是当我像这样分开写入和读取规则时:

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

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

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 分钟后生效从您设置规则的那一刻起。祝你好运。

关于angular - Firebase Cloud Storage : permission denied. 在检索 downloadURL 时无法执行此操作 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50432995/

相关文章:

dependency-injection - 找不到 Angular2 http 服务

angular - 我想在primeng p-table分页中显示 "All"作为一个选项

android - 如何在 firebase 中增加数字

node.js - 来自ActivatedRoute参数的Angular 4原始字符串

Angular2 Router - 有条件地隐藏链接

ios - Firebase 架构 x86_64 的 undefined symbol

firebase - 使用 ngrx 找出 firestore

javascript - 异步/等待上传任务

android - 为什么我无法在 Android Studio 中显示 URL 中的图像?

firebase - 在 Firebase Google Cloud Storage Bucket 上配置 CORS