首页 > 解决方案 > 公开 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));
  }

标签: google-cloud-platformgoogle-cloud-storage

解决方案


推荐阅读