Storage Writer
This guide shows you how to work with Google Cloud Functions locally using the Firebase Emulator Suite and Python. This lab demonstrates how to create an HTTP-triggered function that uploads files to Cloud Storage.
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
- Without Dev Containers, you also need to install:
- Node.js 18+.
- Java 17+.
- Firebase CLI.
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in ContainerTerminal window pip3 install uv && uv sync -
Set up the functions virtual environment:
Terminal window python3.12 -m venv functions/venv && functions/venv/bin/pip install -r functions/requirements.txt -
Start Firebase Emulators:
Terminal window firebase emulators:start -
Run the Example:
Terminal window python test_function.pyTerminal window curl -X POST http://localhost:5001/demo-project/us-central1/upload_file \-H "Content-Type: application/json" \-d '{"filename": "test.txt", "content": "Hello from curl!"}'
Validate results
Section titled “Validate results”Open the Firebase Emulator UI and navigate to the Storage tab to verify the uploaded file:
http://localhost:4000/storageClean Up
Section titled “Clean Up”Stop the emulators by pressing Ctrl+C in the terminal running firebase emulators:start. To clear emulator data:
rm -rf .firebase