This article shows how to serve files with Google Cloud Run. There are a few reasons to use Cloud Run instead of Google Cloud Storage.

  • To learn how to deploy a simple file sharing service using Cloud Run.
  • To have a method of measuring performance. You can have a variety of file sizes in your image to test downloads with.
  • You don’t want to bother with the issues of public file permissions with Cloud Storage.
  • Using Cloud Run is so simple to set up. You can share your vacation photos with family and friends in 30 minutes.
  • Setup a custom domain name if you own your own domain.

Download Git Repository

I have published the files for this article on GitHub.

License: MIT License

Clone my repository to your system:

Getting Started

Verify that the correct project is the default project:

If the correct project is not displayed, use this command to change the default project:

You can list the projects in your account. Some security configurations will not allow you to list projects. In that case, you will need to specify the default project manually as shown above.

Setup files for sharing

Inside the repository is a directory named “data”. This directory is the home directory for file sharing. Copy files to this directory. Subdirectories are supported, so you can have a tree of files.

Review the program source code

The key Go package is net/http. This library provides the entire File Server interface.

Setup the build scripts

Change directories to scripts-windows. Edit the file env.bat. Change any of the environment variables. The important one is GCP_NAME as this will be the name for the Cloud Run service. Provided that the Cloud SDK is set up correctly with credentials and default Project ID, the script will build everything automatically.

To build the image and deploy to Cloud Run, execute the command: build.bat.


I write free articles about technology. Recently, I learned about which provides free images. The image in this article is courtesy of Pixabay at Pexels.