This page shows you how to read object data from your Cloud Storage buckets directly into application memory or interactively in your web browser or command-line terminal. Reading objects into memory or interactively is recommended when you want to stream, inspect, or process data in a way that avoids the CPU, disk I/O, and latency overhead associated with writing files into a persistent local file system.
For instructions on downloading objects into persistent or local storage, see Download objects. For a conceptual overview of object reads and downloads, see Object reads and downloads.
Required roles
To get the permissions that you need to read object data, ask your administrator to grant you the following IAM roles:
- Storage Object Viewer (
roles/storage.objectViewer) on the bucket - Storage Admin (
roles/storage.admin) on the project (only required for reading object data by using the Google Cloud console)
For more information about granting roles, see Manage access to projects, folders, and organizations.
The Storage Object Viewer (roles/storage.objectViewer) role contains the
storage.objects.get permission, which is required for reading objects. The
Storage Admin (roles/storage.admin) role contains the storage.buckets.list
and storage.buckets.get permissions, in addition to the storage.objects.get
permission. These permissions are required for listing the buckets in a project
and viewing information about the buckets. The Storage Admin
(roles/storage.admin) role that includes these permissions is only required
when you want to read objects interactively using the Google Cloud console.
You might also be able to get these permissions with custom roles or other predefined roles.
For instructions on granting roles on buckets, see Set and manage IAM policies on buckets.
Read objects programmatically into memory
This section describes how to read object data by streaming the object bytes directly into application memory.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Rust
Read objects interactively
This section describes how to read objects interactively in your
Google Cloud console browser window or command-line terminal stdout.
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the bucket list, click the name of the bucket whose contents you want to view.
On the Objects tab, click the name of the object you want to read.
On the Object details page, click the public URL or the authenticated URL of the object to read its data.
Command line
To stream an object's byte payload directly into your terminal stdout,
use the gcloud storage cat command:
gcloud storage cat gs://BUCKET_NAME/OBJECT_NAME
Replace the following:
BUCKET_NAME: the name of the bucket that contains the object you want to read. For example,my-bucket.OBJECT_NAME: the name of the object that you want to read. For example,dog.png.
REST APIs
To read an object's bytes and direct the output stream to your terminal
stdout, use the following instructions.
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the JSON API with anobjects.getrequest that includes the-o -option and thealt=mediaquery parameter:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -o - \ "https://storage./storage/v1/b/BUCKET_NAME/o/OBJECT_NAME?alt=media"
Replace the following:
BUCKET_NAME: the name of the bucket that contains the object you want to read. For example,my-bucket.OBJECT_NAME: the URL-encoded name of the object you want to read. For example,pets/dog.png, URL-encoded aspets%2Fdog.png.
XML API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader.Use
cURLto call the XML API with aGETObject request:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage./BUCKET_NAME/OBJECT_NAME"
Replace the following:
BUCKET_NAME: the name of the bucket containing the object you want to read. For example,my-bucket.OBJECT_NAME: the URL-encoded name of the object you want to read. For example,pets/dog.png, URL-encoded aspets%2Fdog.png.