Created
June 26, 2020 05:16
-
-
Save peterkracik/1748f74b87c8b6036dbc0a83fd337c86 to your computer and use it in GitHub Desktop.
Getting a file from bucket as a stream
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 admin from 'firebase-admin'; | |
| admin.initializeApp({ | |
| credential: admin.credential.applicationDefault() | |
| }); | |
| exports.downloadFile = httpRequest.onRequest((req, res) => { | |
| const bucket = admin.storage().bucket('my_bucket'); // initialize storage as admin | |
| const stream = bucket.file('path/to/file.jpg').createReadStream(); // create stream of the file in bucket | |
| // pipe stream on 'end' event to the response | |
| return stream | |
| .on('end', (data: any) => {}) | |
| .pipie(res); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment