Created
June 26, 2020 05:08
-
-
Save peterkracik/45ef021967fdd159af5c71e0da88bd82 to your computer and use it in GitHub Desktop.
FIrebase - get signed url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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