在Firebase存储中访问没有令牌的网址

Jun*_*tae 3 firebase firebase-realtime-database firebase-storage

我有一个firebase存储下载网址,比如

https://firebasestorage.googleapis.com/v0/b/siren-5eee7.appspot.com/o/profile%2FC6jNlR0F4cZBPv7wF0REWUNVor33?alt=media&token=63a9130e-2ba6-4f38-ac3f-2231c54a1043

如何在没有令牌参数的情况下访问此网址?

例如,如果我在没有令牌的情况下访问上面的url,则会显示403错误,显示允许拒绝.

我的firebase存储安全规则如下:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

此文件位于/etc文件中.我该怎么做?

the*_*ene 16

据我了解,您正试图将整个存储桶公开。使用 Firebase 访问规则可能不是最好的,您可能希望通过 Google Cloud 的存储层提供存储桶读取访问权限。

为此,最简单的方法之一是使用Google Cloud Console Storage

选择存储桶,单击要配置的存储桶并打开权限选项卡。由于这是 Firebase 管理的存储桶,因此它将具有 Google 所谓的细粒度访问控制。不用担心,添加公共访问权限非常简单。单击“添加成员”按钮,然后在侧边栏上添加allUsers为新成员,并赋予其“存储”>“存储对象查看器”角色。您可以在存储文档中查看更多详细信息。

这将使存储桶可通过 公开查看<bucketname>.storage.googleapis.com。如果您在 Firebase 中创建了与您拥有并在Google Search Console中验证的域相匹配的额外存储桶,则可以创建一个以您的自定义域命名的存储桶,并使用指向的自定义域的 CNAME 公开访问它c.storage.googleapis.com.(这只会适用于 HTTP,不适用于 HTTPS)。您可以在Storage Endpoints Docs中查看更多详细信息,Google Cloud 的文档比我解释得更好。希望这可以帮助!


aof*_*dev 7

尝试改变规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read;
      allow write: if request.auth != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 即使将规则更改为此,媒体令牌仍然会显示。知道为什么吗? (5认同)
  • 这并不能解决问题。更改该规则不会产生任何影响。 (3认同)

Lin*_*adu 6

如果您需要allow accessing only the images没有令牌的规则,您必须执行以下操作:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if request.auth!=null || resource.contentType.matches('image/.*');
      allow write: if request.auth!=null;
    }
  }
}

Run Code Online (Sandbox Code Playgroud)