


Creating a Local Environment to Operate GCS Emulator from Flask
When creating an application that manipulates GCS (Google Cloud Storage) through Flask on Cloud Run, I wanted to use a GCS emulator in the local environment. This document describes how to set up such an environment.
Emulator to Use
- fsouza/fake-gcs-server
Sample code
I created sample code in the following repository. By following the instructions in README.md, you can use the GCS emulator in a local environment to upload, download, and delete files.
Since you can start everything simply by cloning the repository and running make up, setup is straightforward.
- flask-gcs
Contents of docker-compose.yml
To use the GCS emulator in the Flask container, the STORAGE_EMULATOR_HOST environment variable is set:
services: app: environment: - STORAGE_EMULATOR_HOST=http://gcs:4443
Configuring Flask’s StorageClient
The STORAGE_EMULATOR_HOST environment variable is checked to determine whether to use the emulator:
def get_storage_client(): emulator_host = Config.STORAGE_EMULATOR_HOST if emulator_host: client = storage.Client( credentials=AnonymousCredentials(), project="test", ) else: client = storage.Client() return client
Conclusiuon
When building an application on Cloud Run that manipulates GCS through Flask, you might want to use a GCS emulator in your local environment. These are the setup steps. Note that in production you will not use the GCS emulator, so simply do not set the STORAGE_EMULATOR_HOST environment variable, specify your BUCKET_NAME, and grant the appropriate permissions to Cloud Run.
The above is the detailed content of Creating a Local Environment to Operate GCS Emulator from Flask. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

Fastapi ...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...
