我们正在使用@google-cloud/storage
@ 2.3.1
,并希望公开上传文件。
根据此示例,我们使用createWriteStream
方法创建File对象:
gcFile.createWriteStream({
predefinedAcl: 'publicRead',
});
但是,文件仍在Not public
列中显示Public access
:
我们决定在根据API reference创建流时尝试使用public
布尔值(实际上是上述方法的别名)-文件不会导致可公开访问:
gcFile.createWriteStream({
public: true,
});
接下来,我们尝试在makePublic
对象上使用File
方法将文件公开:
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级别上设置公共访问权限来使文件公开,但我们确实希望它在每个对象级别上。我们如何才能使其正常工作?
答案 0 :(得分:1)
答案 1 :(得分:1)
这是一个错误,已于昨天解决。感谢您提出问题!
干杯!