Skip to content
Start here

Get Object

r2.buckets.objects.get(strobject_key, ObjectGetParams**kwargs) -> BinaryResponseContent
GET/accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key}

Retrieves an object from an R2 bucket. Returns the object body along with metadata headers.

For most workloads, we recommend using R2’s S3-compatible API or a Worker with an R2 binding instead.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
account_id: str

Account ID.

maxLength32
bucket_name: str

Name of the bucket.

maxLength64
minLength3
object_key: str

The key (name) of the object to retrieve. May contain slashes for path-like keys. Slashes (/) within the key MUST be sent literally and MUST NOT be percent-encoded (i.e. %2F); other reserved characters should be percent-encoded as usual.

jurisdiction: Optional[Literal["default", "eu", "fedramp"]]

Jurisdiction where objects in this bucket are guaranteed to be stored.

One of the following:
"default"
"eu"
"fedramp"
if_modified_since: Optional[str]

Returns the object only if it has been modified since the specified time. Must be formatted as an HTTP-date (RFC 7231), e.g. Tue, 15 Jan 2024 10:30:00 GMT.

if_none_match: Optional[str]

Returns the object only if its ETag does not match the given value.

ReturnsExpand Collapse
BinaryResponseContent

Get Object

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
object = client.r2.buckets.objects.get(
    object_key="path/to/my-object.txt",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    bucket_name="example-bucket",
)
print(object)
content = object.read()
print(content)
Returns Examples