Stay organized with collections Save and categorize content based on your preferences.
You can use Cloud Storage to store and serve files, such as movies or images or other static content.
This document describes how to use the Cloud Client Libraries for Cloud Storage in your app to store data and retrieve data from Cloud Storage.
Before you beginMake sure you create a Cloud Storage bucket for your application by invoking the following command:
gcloud storage buckets create gs://YOUR_BUCKET_NAME
Make the bucket publicly readable so it can serve files:
gcloud storage buckets add-iam-policy-binding gs://<var>YOUR_BUCKET_NAME</var> --member=allUsers --role=roles/storage.objectViewer
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/golang-samples.git
cd golang-samples/appengine_flexible/storage
Java
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
cd java-docs-samples/flexible/java-17/cloudstorage
Node.js
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples/
cd nodejs-docs-samples/appengine/storage/flexible
PHP
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/php-docs-samples
cd php-docs-samples/appengine/flexible/storage
Python
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
cd python-docs-samples/appengine/flexible/storage
Ruby
To clone the repository:
git clone https://github.com/GoogleCloudPlatform/ruby-docs-samples
cd ruby-docs-samples/appengine/flexible/storage/
.NET
Download the sample app and extract it.
If you're using the command line, navigate into the following app directory:
dotnet-docs-samples\appengine\flexible\CloudStorage\CloudStorage.Sample
To run your application locally, set up a service account and download credentials:
Open the list of credentials in the Google Cloud console.
Click Create credentials.
Select Service account key.
A Create service account key window opens.
Click the Service account list, and select Compute Engine default service account.
Select JSON for the Key type.
Click Create.
A New private key window is displayed and the private key for the is downloaded automatically.
Click Close.
Note: When you create the service account, choose Compute Engine default service account and leave JSON selected under Key Type.In app.yaml
, set GCLOUD_STORAGE_BUCKET
. This value is the name of the Cloud Storage bucket you created previously.
In app.yaml
, set the BUCKET_NAME
to the Cloud Storage you previously created for your project.
In pom.xml
, set com.google.cloud
as a dependency, and specify google-cloud-storage
as the artifactID for that dependency; this provides the functions to use Cloud Storage.
In app.yaml
, add your project ID to the GOOGLE_CLOUD_PROJECT
environment value. Then set the GCLOUD_STORAGE_BUCKET
environment value to the name of the Cloud Storage bucket you created previously.
In package.json
, add @google-cloud/storage
as a dependency, which provides the functions to use Cloud Storage.
See the README.md
file for instructions on running and testing locally.
In app.yaml
, set CLOUD_STORAGE_BUCKET
; this value is the name of the Cloud Storage bucket you created previously.
In composer.json
, notice that you must include the Cloud Client library, because this provides Cloud Storage functions.
In app.yaml
, set GOOGLE_STORAGE_BUCKET
; this value is the name of the Cloud Storage bucket you created previously.
In requirements.txt
, notice that you must include the google-cloud-storage
library, because this provides Cloud Storage functions.
In app.yaml
, set the GCLOUD_STORAGE_BUCKET
to the Cloud Storage you previously created for your project.
Note that you must include the gcloud
library in Gemfile
to use Cloud Storage functions.
In app.yaml
file , set the TEST_GOOGLE_BUCKET_NAME
to the Cloud Storage you previously created for your project.
env_variables:
TEST_GOOGLE_BUCKET_NAME: [your-bucket-name]
Application code Go
The sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler writes the file to the Cloud Storage bucket using Cloud Storage NewWriter function.
Notice that to retrieve this file from Cloud Storage, you will need to specify the bucket name and the filename. You should store these values in your app for future use.
JavaThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the doPost
request handler writes the file to the Cloud Storage bucket using Storage.create
Notice that to retrieve this file from Cloud Storage, you will need to specify the bucket name and the filename. You should store these values in your app for future use.
Node.jsThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler loads the file content into a blob and writes it to Cloud Storage.
Notice that after the file is uploaded to Cloud Storage, the public URL to this file is returned, which you can use to serve the file directly from Cloud Storage. You should store this value in your app for future use.
PHPThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler loads the file content into a blob and writes it to Cloud Storage.
Notice that after the file is uploaded to Cloud Storage, the public URL to this file is returned, which you can use to serve the file directly from Cloud Storage. You should store this value in your app for future use.
PythonThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler loads the file content into a Cloud Storage blob and writes it to the Cloud Storage bucket.
Notice that after the file is uploaded to Cloud Storage, the public URL to this file is returned, which you can use to serve the file directly from Cloud Storage. You should store this value in your app for future use.
RubyThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler loads the file content into a blob and writes it to Cloud Storage.
Notice that after the file is uploaded to Cloud Storage, the public URL to this file is returned, which you can use to serve the file directly from Cloud Storage. You should store this value in your app for future use.
.NETThe sample application presents a web page prompting the user to supply a file to be stored in Cloud Storage. When the user selects a file and clicks submit, the upload handler loads the file content into a blob and writes it to Cloud Storage.
Notice that after the file is uploaded to Cloud Storage, the public URL to this file is returned, which you can use to serve the file directly from Cloud Storage. You should store this value in your app for future use.
For more informationFor complete information on Cloud Storage, see the Cloud Storage documentation.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document explains how to use Cloud Storage to store and retrieve files, such as images and other static content, using the Cloud Client Libraries for Cloud Storage."],["Before starting, users need to set up their development environment, create a Cloud Storage bucket, and make it publicly readable."],["Sample code is provided for multiple programming languages, including Go, Java, Node.js, PHP, Python, Ruby, and .NET, with instructions on how to clone the repository and set up dependencies."],["Each language's application code demonstrates how to create a web page for users to upload files, then it uploads the files to a Cloud Storage bucket, and finally it returns a public URL to access the file."],["Users will need to set bucket names in the application configuration, and the instructions walk you through the necessary steps for each language."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4