Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Objects: get

Retrieves objects or their associated metadata. Try it now or see an example .

The authenticated user must have READER permissions on the object. To retrieve the acl property, the authenticated user must have OWNER permissions on the object.

Request

HTTP request

GET https://www.googleapis.com/storage/v1beta2/b/bucket/o/object

Parameters

Parameter name Value Description
Path parameters
bucket string Name of the bucket in which the object resides.
object string Name of the object.
Optional query parameters
generation unsigned long If present, selects a specific revision of this object (as opposed to the latest version, the default).
ifGenerationMatch unsigned long Makes the operation conditional on whether the object's generation matches the given value.
ifGenerationNotMatch unsigned long Makes the operation conditional on whether the object's generation does not match the given value.
ifMetagenerationMatch unsigned long Makes the operation conditional on whether the object's current metageneration matches the given value.
ifMetagenerationNotMatch unsigned long Makes the operation conditional on whether the object's current metageneration does not match the given value.
projection string Set of properties to return. Defaults to noAcl .

Acceptable values are:
  • " full ": Include all properties.
  • " noAcl ": Omit the acl property.

Request body

Do not supply a request body with this method.

Response

By default, this responds with an object resource in the response body. If you provide the URL parameter alt=media , then it will respond with the object data in the response body. If you use alt=media , then you can use the Range HTTP header to specify the portion of the object you wish to retrieve.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library .

Storage.Objects.Get getObject = storage.objects().get("mybucket", "myobject");

if (getMetadata == true) {
  StorageObject object = getObject.execute();
} else {
  // Downloading data.
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  // If you're not in AppEngine, download the whole thing in one request, if possible.
  getObject.getMediaHttpDownloader().setDirectDownloadEnabled(!IS_APP_ENGINE);
  getObject.executeMediaAndDownloadTo(out);
}

Python

Uses the Python client library .

# Get Metadata
req = client.objects().get(
        bucket=bucket_name,
        object=object_name,
        fields='bucket,name,metadata(my-key)',    # optional
        generation=generation)                    # optional
resp = req.execute()
print json.dumps(resp, indent=2)

# Get Payload Data
req = client.objects().get_media(
        bucket=bucket_name,
        object=object_name,
        generation=generation)    # optional
# The BytesIO object may be replaced with any io.Base instance.
fh = io.BytesIO()
downloader = http.MediaIoBaseDownload(fh, req, chunksize=1024*1024)
done = False
while not done:
    status, done = downloader.next_chunk()
    if status:
        print 'Download %d%%.' % int(status.progress() * 100)
    print 'Download Complete!'
print fh.getvalue()

Ruby

Uses the Ruby client library .

# Get a specific object from a bucket
bucket_get_result = client.execute(
  api_method: storage.objects.get,
  parameters: {bucket: BUCKET, object: OBJECT}
)
puts "Contents of #{OBJECT} in #{BUCKET}: "
puts bucket_get_result.body

Go

Uses the Go client library .

// Get an object from a bucket.
bucketName := "BUCKET_NAME"
result, err := service.Objects.Get(bucketName, "OBJECT_NAME").Do()
fmt.Printf("The media download link for %v/%v is %v.\n",
	bucketName, result.Name, result.MediaLink)

Try it!

Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer .

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.