我一直在尝试搜索文档,我想我找到了一个解决方案,但它不起作用,我继续遇到错误。我正在为 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));
}