【发布时间】:2020-09-13 23:58:30
【问题描述】:
我有两个图像文件上传到 Firebase 存储:
capsule house.jpg 是通过 UI 上传的(点击上传文件按钮)。
upload_64e8fd... 正在使用这个从我的后端服务器 (node.js) 上传:
const bucket = fbAdmin.storage().bucket('gs://assertivesolutions2.appspot.com');
const result = await bucket.upload(files.image.path);
capsule house.jps 被识别为 jpeg,并且在右侧空白处提供了指向它的链接。如果我单击它,我会在新选项卡中看到我的图像。你可以自己看看:
upload_64e8fd... 不被识别为任何类型的图像文件,也没有提供链接。
后端返回的结果是一个巨大的json对象,包含以下字段:
"selfLink": "https://www.googleapis.com/storage/v1/b/assertivesolutions2.appspot.com/o/upload_64e8fd09f787acfe2728ae73158e20ab"
"mediaLink": "https://storage.googleapis.com/download/storage/v1/b/assertivesolutions2.appspot.com/o/upload_64e8fd09f787acfe2728ae73158e20ab?generation=1590547279565389&alt=media"
第一个将我带到这样的页面:
{
"error": {
"code": 401,
"message": "Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.",
"errors": [
{
"message": "Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.",
"domain": "global",
"reason": "required",
"locationType": "header",
"location": "Authorization"
}
]
}
}
第二个给了我类似的东西:
Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.
我的存储桶的规则如下:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
我允许所有读取和写入。
那么为什么它说当我的图片通过我的后端服务器上传时我无权查看我的图片?
我也想知道为什么它在通过我的后端服务器上传时无法识别为 jpeg,但在通过 UI 上传时却识别为 jpeg,但我想关注此访问问题问题。
谢谢。
【问题讨论】:
-
只有 Firebase 的客户端(iOS、Android、Web)会生成允许公共访问文件的下载 URL。通过 Node.js 客户端上传文件时,不会生成这样的下载 URL,默认情况下无法访问该文件。见stackoverflow.com/questions/42956250/…
-
感谢 Frank 和 gso_gabriel 提供的链接。有很多东西要通读,当我读完后我会回到这个线程。只是想事先说声谢谢。
标签: node.js google-cloud-storage firebase-storage