Skip to content

Instantly share code, notes, and snippets.

@peterkracik
Created June 26, 2020 05:08
Show Gist options
  • Select an option

  • Save peterkracik/45ef021967fdd159af5c71e0da88bd82 to your computer and use it in GitHub Desktop.

Select an option

Save peterkracik/45ef021967fdd159af5c71e0da88bd82 to your computer and use it in GitHub Desktop.
FIrebase - get signed url
import * as functions from 'firebase-functions';
import { Storage, GetSignedUrlConfig } from '@google-cloud/storage';
exports.getUrl = functions.https.onCall(async (data, context) => {
const storage = new Storage();
// options of temporary access to file
const options: GetSignedUrlConfig = {
version: 'v2', // default value
action: 'read', // read | write | delete | resumable
expires: Date.now() + 1000 * 60 * 60, // expire date, one minute from now
};
// get a V2 signed URL for the file
const [url] = await storage
.bucket('my_bucket') // name of the storage bucket
.file('path/to/my/file.jpg') // path of the file inside the bucket
.getSignedUrl(options) // returns a promise
return url
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment