node.js - 为什么我无法访问我的 Firebase 存储映像?
问题描述
我有两个图像文件上传到 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 上传时它会识别它,但我想关注这个问题的访问问题。
谢谢。
解决方案
默认情况下,文件作为私有文件上传,除非您更改存储桶设置,如此处所述。以下代码是如何更改文档可见性的示例。
/**
* {@inheritdoc}
*/
public function setVisibility($path, $visibility)
{
$object = $this->getObject($path);
if ($visibility === AdapterInterface::VISIBILITY_PRIVATE) {
$object->acl()->delete('allUsers');
} elseif ($visibility === AdapterInterface::VISIBILITY_PUBLIC) {
$object->acl()->add('allUsers', Acl::ROLE_READER);
}
$normalised = $this->normaliseObject($object);
$normalised['visibility'] = $visibility;
return $normalised;
}
您可以按照官方文档中的教程检查如何通过控制台进行设置:公开数据
除此之外,正如@FrankvanPuffelen 的评论中所指出的那样,您将不会生成要访问的文件的 URL。您可以在此处找到有关它的更多信息。
让我知道这些信息是否对您有帮助!
推荐阅读
- php - 在laravel中将查询放入带有条件的for循环中
- sql - 查找列值链
- c - Paho mqtt 客户端连接丢失
- postgresql - 找不到数据库的DriverClass:将postgresql导出到S3时的极光
- php - 在 WooCommerce 中动态更改产品价格
- powershell - Powershell 将函数返回的值存储到变量中
- php - Paypal Payments Pro Sandbox 错误 很抱歉,我们现在无法完成您的付款。请稍后再试
- php - laravel 试图从控制器内的模型中获取非对象的属性
- ios - MQTT 协议 NGINX
- sql-server - 从另一个 WebAPI 连续调用 WebAPI