Skip to content

Instantly share code, notes, and snippets.

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

  • Save peterkracik/1748f74b87c8b6036dbc0a83fd337c86 to your computer and use it in GitHub Desktop.

Select an option

Save peterkracik/1748f74b87c8b6036dbc0a83fd337c86 to your computer and use it in GitHub Desktop.
Getting a file from bucket as a stream
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