Cloud Functions: how to upload additional file for use in code?
I find this way the easiest when it comes to Firebase Functions:
- Put your .proto file into functions folder of your firebase project (where index.js and package.json is located).
- Deploy your functions as normal with the CLI command
firebase deploy --only functions
As you can see here the file is automatically added to the project in the GCP:
And you can access it in your node.js project:
protobuf.load(__dirname + '/schema.proto')
When you are using Firebase Cloud Functions with TypeScript (your code is in functions/src/index.ts
), you need to put the additional files in functions/lib
You'd like to upload 3 files to deploy your Cloud Function:
- index.js
- package.json
- prediction_service.proto
In order to do so via the Developer Console, you'll need to:
- Go to the Google Cloud Developer Console > Cloud Functions > Create Function
- In the "Source Code" field, choose either:
- "ZIP upload" and select a zip file including your 3 files,
- "ZIP from Cloud Storage" and select file location on GCS,
- "Cloud Source repository" and provide your repo details
- Fill in the remaining fields and click "Create"
Once deployed, in the source tab for your function you'll see the three files displayed.
Alternatively, you can use gcloud to deploy your files via the following command:
gcloud beta functions deploy <functionName> --source=SOURCE
where source can be a ZIP file on Google Cloud Storage, a reference to source repository or a local filesystem path. I'd recommend to have a look at the doc for this command for full details.