Raf*_*fie 7 firebase firebase-storage angular
我有一个功能可以成功将图像上传到我的云存储桶。
使用另一个功能,我想获取图像的URL以显示在我的页面上(使用<img.../>)
getImageUrl(id: string) {
return this.storageRef.child('X/' + id ).getDownloadURL();
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时..我得到一个“无效” URL,当我复制该URL并转到它时,得到以下消息:
{
"error": {
"code": 403,
"message": "Permission denied. Could not perform this operation"
}
}
Run Code Online (Sandbox Code Playgroud)
我在某处读到这可能是因为URL中没有附加令牌,但是如何启用它呢?
小智 6
最近几天,我一直在尝试了解Firebase存储规则,但我不知道为什么,但是当我分开编写和阅读这样的规则时,例如:
allow write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;
allow read: if true;
Run Code Online (Sandbox Code Playgroud)
该代码很好用,我可以使用getDownloadURL()进行读写,但是当我像这样一起使用它们时:
allow read, write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;
Run Code Online (Sandbox Code Playgroud)
我遇到了与您相同的错误:
{
"error": {
"code": 403,
"message": "Permission denied. Could not perform this operation"
}
Run Code Online (Sandbox Code Playgroud)
}
我可以在将它们一起使用时进行书写,但是当我尝试使用getDownloadURL()读取文件时,就会出现问题。也许您可以尝试按我提到的方法将规则分开,看看是否可行。我希望它能解决您的问题。另外,不要忘记,规则是5分钟后现场 的那一刻起,你设置。祝好运。
小智 0
您需要使用 getDownloadURL 方法。这将允许您获取下载图像或在您自己的 html 中引用所需的 URL。
请参阅下面的参考文档:
https://firebase.google.com/docs/storage/web/download-files#download_data_via_url
| 归档时间: |
|
| 查看次数: |
7902 次 |
| 最近记录: |