首页 > 解决方案 > x-googl-acl 没有公开上传的文件

问题描述

目前我一直在尝试将对象(视频)上传到我的 Google Storage Cloud。我已经发现(可能)我无法将它们公开的原因是由于ACL or IAM许可。目前完成的方式是我从后端得到一个signedUrl

const getGoogleSignedUrl = async (root, args, context) => {
  const { filename } = args;
  const googleCloud = new Storage({
    keyFilename: ,
    projectId: 'something'
  });

  const options = {
    version: 'v4',
    action: 'write',
    expires: Date.now() + 15 * 60 * 1000, // 15 minutes
    contentType: 'video/quicktime',
    extensionHeaders: {'x-googl-acl': 'public-read'}
  };

  const bucketName = 'something';

  // Get a v4 signed URL for uploading file
  const [url] = await googleCloud
    .bucket(bucketName)
    .file(filename)
    .getSignedUrl(options);

  return { url };
}

一旦我从后端获得临时许可作为 url,我尝试发出 put 请求将文件上传为:

const response = await fetch(url, {
  method: 'PUT',
  body: blob,
  headers: {
    'x-googl-acl': 'public-read',
    'content-type': 'video/quicktime'
  }
}).then(res => console.log("thres is ", res)).catch(e => console.log(e));

即使文件确实上传到谷歌云存储。它始终将公共访问显示为Not public. 任何帮助都会有所帮助,因为我开始不明白如何使用谷歌云公开对象。

x-aws-acl在 AWS(以前)中,通过添加到 put 请求很容易使对象公开。

先感谢您。

更新

我已将代码更改为反映当前的外观。此外,当我在上传后查看 Google Storage 中的对象时,我看到了

Public access未经授权

Type视频/快速时间

Size369.1 KB

Created2021 年 2 月 11 日下午 5:49:02

Last modified2021 年 2 月 11 日下午 5:49:02

Hold status没有任何

Retention政策 无

Encryption typeGoogle 管理的密钥

Custom时间——</p>

Public URL不适用

更新 2

就像声明的那样。在尝试添加推荐的标头后我无法上传文件的问题是因为我没有正确提供标头。我将标题更改为x-googl-acl允许x-goog-acl我将其上传到云端。

新问题现在Public access显示为Not authorized

更新 3

为了尝试新事物,我按照此处列出的方向进行操作https://www.jhanley.com/google-cloud-setting-up-gcloud-with-service-account-credentials/。一旦我完成了一切。我采取的下一步是

1 - 将新视频上传到云端。这将使用提供的新 json 来完成

  const googleCloud = new Storage({
    keyFilename: json_file_given),
    projectId: 'something'
  });

文件上传后,我注意到在公开方面没有任何变化。还是有Public access Not authorized

2 - 检查上传对象的状态后,我继续在底部遵循类似的方法,以确保我使用与上传文件的 json 对象相同的帐户。

gcloud auth activate-service-account test@development-123456.iam.gserviceaccount.com --key-file=test_google_account.json

3 - 一旦我注意到我使用了具有正确权限的正确人员,我就执行了下一步

gsutil acl ch -u AllUsers:R gs://example-bucket/example-object

这是返回实际上导致了响应No changes to gs://crit_bull_1/google5.mov

标签: google-cloud-platformgoogle-cloud-storage

解决方案


推荐阅读