How to upload using firebase cloud functions

Tuan Ngo
2 min readJun 15, 2017

--

A small setup guide to integrate google cloud storage and firebase

I have a requirement: when there is change in firebase realtime database’s key1, a firebase cloud function will save data from database’s key2 to firebase storage as a csv file.

This is my note when figure out how to do that with firebase.

Gotchas

  1. There are two ways of upload file to firebase’s storage

Option 1: using firebase client (e.g. web client) : https://firebase.google.com/docs/storage/web/upload-files

Option 2: using firebase cloud function. The problem with firebase newbie like me is the tutorial and code example is not quite straight in setup steps.

2. Firebase storage is a wrapper for Google Cloud Storage

https://firebase.google.com/docs/storage/gcp-integration .

If you try firebase console and google cloud console , you will see the same set of upload files

so we need to learn google cloud storage api for this task

Solution

I start from this example and this guide, but soon face two issues for integration my firebase with google cloud storage:

  • How to authenticate with google cloud storage?
  • What is the google storage’s bucket name?

For the former question, actually I can use my service account json file from firebase

We can generate one using firebase admin UI.

For later question, the bucket name is right in firebase’s storage menu.

Environment config

It’s great if I can config the keyFilename and bucket name above, so I can switch between test and production environments without changing code. And firebase environment configuration allows me to do that using firebase cli.

--

--