Make a Google Cloud signed url public

Viewed 180

I have been trying to search through the documentations and I think I found a solution but it isn't working and I continue to get an error. What I am doing for a signedUrl is

  const [url] = await googleCloud
    .bucket(bucketName)
    .file(filename)
    .makePublic()
    .getSignedUrl(options);

  return { url };

What I added from what I found in the docs was makePublic() but this throws and error as it is followed by getSignedUrl. I don't have any problem if I remove makePublic() and upload the file from the signed url but the file won't be public.

Any advice on how I should proceed?

UPDATE

The error I am seeing when trying to get a signed url with makePublic is [Unhandled promise rejection: Error: googleCloud.bucket(...).file(...).makePublic(...).getSignedUrl is not a function].

Additional information in regards to the options being send with getSignedUrl function are

  const options = {
    version: 'v4',
    action: 'write',
    expires: Date.now() + 15 * 60 * 1000, // 15 minutes
    contentType: 'video/quicktime',
  };

UPDATE (How frontend handles signed 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));
  }
0 Answers
Related