Let's say you have a CSV file someone uploads from a UI, that gets saved to Firebase storage; details on how to do this here.
How do you then read and process that file on the server?
You can access the bucket from the firebase-admin
library, and then download the file in memory. What you do with the file then is up to you!
import functions from 'firebase-functions';
import { initializeApp } from 'firebase-admin/app';
import { getStorage } from 'firebase-admin/storage';
initializeApp();
export const processCSV = functions
.runWith({
timeoutSeconds: 540
})
.storage.object()
.onFinalize(async object => {
functions.logger.log(object);
const bucket = getStorage().bucket();
const csvFile = await bucket.file(object.name).download();
functions.logger.log(csvFile.toString());
});