Skip to content
Start here

Get Object

client.r2.buckets.objects.get(stringobjectKey, ObjectGetParams { account_id, bucket_name, jurisdiction, 2 more } params, RequestOptionsoptions?): Response
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
objectKey: string

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.

params: ObjectGetParams { account_id, bucket_name, jurisdiction, 2 more }
account_id: string

Path param: Account ID.

maxLength32
bucket_name: string

Path param: Name of the bucket.

maxLength64
minLength3
jurisdiction?: "default" | "eu" | "fedramp"

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

One of the following:
"default"
"eu"
"fedramp"
ifModifiedSince?: string

Header param: 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.

ifNoneMatch?: string

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

ReturnsExpand Collapse
unnamed_schema_7 = Response

Get Object

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const object = await client.r2.buckets.objects.get('path/to/my-object.txt', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  bucket_name: 'example-bucket',
});

console.log(object);

const content = await object.blob();
console.log(content);
Returns Examples