问题描述
目前我一直在尝试将对象(视频)上传到我的 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
。任何帮助都会有所帮助,因为我开始不明白如何使用谷歌云公开对象。
在 AWS(以前)中,通过向放置请求添加 x-aws-acl
可以轻松地将对象设为公开。
提前致谢。
更新
我已更改代码以反映当前的样子。此外,当我在上传后查看 Google Storage 中的对象时,我看到
Public access
未授权
Type
视频/quicktime
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
次 —
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
的响应
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)