google-cloud-platform - 公开 Google Cloud 签名的网址
问题描述
我一直在尝试搜索文档,我想我找到了一个解决方案,但它不起作用,我继续收到错误。我为 signedUrl 做的是
const [url] = await googleCloud
.bucket(bucketName)
.file(filename)
.makePublic()
.getSignedUrl(options);
return { url };
我从我在文档中找到的内容中添加的是makePublic()
,但这会引发和错误,因为它后面跟着getSignedUrl
. makePublic()
如果我从签名的 url 中删除并上传文件,但文件不会公开,我没有任何问题。
关于我应该如何进行的任何建议?
更新
我在尝试使用签名 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',
};
更新(前端如何处理签名的 url)
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));
}
解决方案
推荐阅读
- php - str_replace 网址不起作用
- javascript - VizFrame 柱形图的 y 轴刻度为 500m
- r - 映射地理坐标的方法,用于在另一个经度和经度配置文件中标记数据?
- c++ - 无法分配抽象类型“解析器”的对象
- c# - C# COMException: 无法调用
从事件内部 - google-cloud-platform - 在 Google Datalab 中运行“gcloud ml-engine”命令时出现语法错误
- python - 在 Windows 上运行的 shell 脚本的输出包含提示
- mysql - mysql for mac,创建数据库 ERROR 3680 (HY000)
- android - Android:MediaCodec:dequeueBuffer 失败:BAD_VALUE(-22)
- reactjs - 反应原生错误 fsevents@1.2.4 (node_modules\fsevents