Node.js 为什么我无法访问firebase存储映像?
我已将两个图像文件上载到firebase存储: capsule house.jpg是通过用户界面点击上传文件按钮上传的 上传\u 64e8fd。。。正在使用以下命令从我的后端服务器node.js上载:Node.js 为什么我无法访问firebase存储映像?,node.js,google-cloud-storage,firebase-storage,Node.js,Google Cloud Storage,Firebase Storage,我已将两个图像文件上载到firebase存储: capsule house.jpg是通过用户界面点击上传文件按钮上传的 上传\u 64e8fd。。。正在使用以下命令从我的后端服务器node.js上载: const bucket = fbAdmin.storage().bucket('gs://assertivesolutions2.appspot.com'); const result = await bucket.upload(files.image.path); capsule house
const bucket = fbAdmin.storage().bucket('gs://assertivesolutions2.appspot.com');
const result = await bucket.upload(files.image.path);
capsule house.jps被识别为jpeg,其链接位于右边空白处。如果我点击它,我会在一个新的标签中看到我的图像。你可以自己看看:
上传\u 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,但我想重点讨论这个问题的访问问题
谢谢。默认情况下,除非您如前所述更改bucket设置,否则文件将作为私有文件上载。下面的代码是如何更改文档可见性的示例
/**
* {@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;
}
您可以按照官方文档中的教程,检查如何通过console进行设置:
除此之外,正如@FrankvanPuffelen的评论所指出的,您将不会为要访问的文件生成URL。你可以找到更多关于它的信息
如果这些信息对你有帮助,请告诉我 只有Firebase iOS、Android和Web的客户端才能生成允许公众访问该文件的下载URL。当您通过Node.js客户端上载文件时,不会生成此类下载URL,并且默认情况下该文件不可访问。谢谢你,弗兰克和加布里埃尔的链接。要通读的内容很多,读完后我会回到这篇文章。我只是想事先说声谢谢。谢谢你们gso_gabriel和Frank的链接。要通读的内容很多,读完后我会回到这篇文章。只是想事先说声谢谢。