即使设置了ACL,也无法公开共享文件对象

时间:2018-12-05 12:54:53

标签: node.js google-cloud-storage

我们正在使用@google-cloud/storage @ 2.3.1,并希望公开上传文件。

根据此示例,我们使用createWriteStream方法创建File对象:

gcFile.createWriteStream({
  predefinedAcl: 'publicRead',
});

但是,文件仍在Not public列中显示Public accessenter image description here

我们决定在根据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中检查了权限。

在编辑权限时,它明确指出该对象是可公开访问的,但是在概述中未显示公共链接吗? enter image description here

我们可以通过在Bucket级别上设置公共访问权限来使文件公开,但我们确实希望它在每个对象级别上。我们如何才能使其正常工作?

2 个答案:

答案 0 :(得分:1)

对我有用的是将 allUsers 添加到存储桶的以下权限中:存储对象查看器,存储旧版对象读取器。

他们不允许公众列出存储桶,而是在存储桶内读取对象。

Permissions on console

答案 1 :(得分:1)

这是一个错误,已于昨天解决。感谢您提出问题!

干杯!