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:
Parameters
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.
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)