Skip to content

Instantly share code, notes, and snippets.

@shaffeeullah
Last active November 1, 2021 21:19
Show Gist options
  • Save shaffeeullah/198749e5cbd5f70cb100ee90b320bea5 to your computer and use it in GitHub Desktop.
Save shaffeeullah/198749e5cbd5f70cb100ee90b320bea5 to your computer and use it in GitHub Desktop.
Generate a Google Cloud Storage Signed URL to download data via GET request
async function getReadSignedUrl(bucketName, filename, minutesToExpiration) {
const storage = new Storage();
const options = {
version: 'v4',
action: 'read',
expires: minutesToExpiration * 60 * 1000 + Date.now(),
};
const [url] = await storage
.bucket(bucketName)
.file(filename)
.getSignedUrl(options);
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment