google-cloud-platform - 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
视频/快速时间
Size
369.1 KB
Created
2021 年 2 月 11 日下午 5:49:02
Last modified
2021 年 2 月 11 日下午 5:49:02
Hold status
没有任何
Retention
政策 无
Encryption type
Google 管理的密钥
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
解决方案
推荐阅读
- reactjs - react-hook-form 输入处理程序耗时太长
- python - 如何为神经网络连接多个矩阵(或重塑)
- r - 如果 r 中小于 0 或大于 0,如何根据条件正确着色 geom_line() 和 geom_point()?
- javascript - 如何停止滚动捕捉过渡的时间
- android - kotlin 中不应该出现的许多错误
- typescript - 如何从原型图生成对象
- linux - 两个 crontab 条目之间的区别
- python - Pandas 将嵌套的 JSON 展平
- linux - 有没有办法使用 Linux 将两个 fasta 文件合并在一起?
- javascript - 使用构造函数Javascript中的字段方法为对象提供最简单的方法