如何解决将 Google Cloud 签名的 url 设为公开
我一直在尝试搜索文档,我想我找到了一个解决方案,但它不起作用,我继续遇到错误。我正在为 signedUrl 做的是
const [url] = await googleCloud
.bucket(bucketName)
.file(filename)
.makePublic()
.getSignedUrl(options);
return { url };
我从文档中发现的内容中添加的是 makePublic()
,但这会引发错误,因为它后跟 getSignedUrl
。如果我删除 makePublic()
并从签名 url 上传文件,但该文件不会公开,我没有任何问题。
关于我应该如何进行的任何建议?
更新
我在尝试使用 makePublic
获取签名网址时看到的错误是 [Unhandled promise rejection: Error: googleCloud.bucket(...).file(...).makePublic(...).getSignedUrl is not a function]
。
有关使用 getSignedUrl
函数发送的选项的其他信息是
const options = {
version: 'v4',action: 'write',expires: Date.Now() + 15 * 60 * 1000,// 15 minutes
contentType: 'video/quicktime',};
更新(前端如何处理签名网址)
const submitReview = async () => {
const url = await getSignedUrl({
variables: { filename: "google3.mov" }
}).then(async response => {
if (response.data && response.data.getSignedUrl) {
const url = response.data.getSignedUrl.url;
const pathUrl = url.split('?');
const videoPath = pathUrl[0];
const uploadedReponse = await uploadToGoogleCloud(url);
}
});
}
const uploadToGoogleCloud = async (url) => {
const videoFile = await fetch(video.uri);
const blob = await videoFile.blob();
const response = await fetch(url,{
method: 'PUT',body: blob
}).then(res => console.log("thres is ",res)).catch(e => console.log(e));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。