Serving up data from Cloud Storage

When it comes to the cloud, there’s more than one way to serve a file. In this post, we’ll walk you through all the ways to serve data from Cloud Storage — so you can determine the best fit for your needs!

You can use Cloud Storage to serve assets to your customers, and depending on your application, there are a variety of methods you might use to get that data out of a Cloud Storage bucket. In this post, we’ll cover four ways to serve those assets, but feel free to read more in the documentation, or for general, conceptual information on uploads and downloads, read this.

Here we go!

Client Libraries

And trust me when I say…we speak your language. With code samples in C++, C#, Go, Java, Node.js, PHP, Python, and Ruby — we’ve got you covered. Check out the documentation for more.

Here’s an example of downloading from your Cloud Storage bucket using Python:

from google.cloud import storage

def download_blob(bucket_name, source_blob_name,

destination_file_name):

“””Downloads a blob from the bucket.”””

# bucket_name = “your-bucket-name”

# source_blob_name = “storage-object-name”

# destination_file_name = “local/path/to/file”

storage_client = storage.Client()

bucket = storage_client.bucket(bucket_name)

blob = bucket.blob(source_blob_name)

blob.download_to_filename(source_file_name)

gsutil

For our purposes, the `cp` command allows you to upload files from your local machine to google cloud.

For example, running *this* command will download from a Cloud Storage bucket to a local path on your device.

Additionally, gsutil comes with a plethora of options to configure to your specific use case; like the `-m` command, which allows for copy options to occur in parallel.

REST APIs

curl -X GET \

-H “Authorization: Bearer OAUTH2_TOKEN” \

-o “SAVE_TO_LOCATION” \

“https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME"

Cloud Console

This is a great way to grab individual files when you’re debugging or going through things manually.

Note: For some object types, selecting “Download” opens the object in the browser. To download these objects to your local computer, right-click on “Download” and select “Save Link As.”

What’s Next?

Learn more about your storage options in Cloud Storage Bytes, or check out the documentation for more information, including tutorials.