【发布时间】:2018-12-05 12:54:53
【问题描述】:
我们正在使用 @google-cloud/storage @2.3.1 并希望公开上传的文件。
我们按照这个例子使用createWriteStream 方法创建我们的文件对象:
gcFile.createWriteStream({
predefinedAcl: 'publicRead',
});
但是,该文件仍然在 Public access 列中显示 Not public:
我们决定在根据API reference(实际上是上面的别名)创建流时尝试使用public 布尔值 - 文件无法公开访问:
gcFile.createWriteStream({
public: true,
});
接下来,我们尝试使用File 对象上的makePublic 方法公开文件:
const file = gcs.bucket('our_bucket_name').file('file_path_here');
await file.makePublic();
const acl = await file.acl.get();
console.log(acl);
这会记录对象的以下 ACL:
[
[
{
entity: 'owner@our-project-name.iam.gserviceaccount.com',
role: 'OWNER'
},
{
entity: 'allUsers',
role: 'READER'
}
],
{
kind: 'storage#objectAccessControls',
items:
[
[Object],
[Object]
]
}
]
所以看起来我们满足了以下条件documented here:
The Access Control List (ACL) for the object includes an entry for
allUsers or allAuthenticatedUsers.
If these conditions are met, the public access column for the object
reads Public.`
但是,该列仍显示为Not public。
虽然权限看起来正确,但我们还通过关注 the steps described here 在 Cloud Console 中检查了权限。
在编辑权限时,它清楚地表明该对象是可公开访问的,但它没有在概述中显示公共链接?
我们可以通过在 Bucket 级别设置公共访问来公开文件,但我们真的很喜欢它在每个对象级别。我们怎样才能让它发挥作用?
【问题讨论】:
-
感谢发帖...同样的事情发生在这里。
-
this page 描述了如何使用以下 url 格式访问公共共享对象(检查 API 链接部分):
http://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]。有趣的是:这确实有效,尽管 Cloud Storage 浏览器仍在Public access列中显示Not public
标签: node.js google-cloud-storage