Objects
Objects stored in an R2 bucket, over Cloudflare's REST API.
List
List objects in a bucket.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
params | array | No | [] | Query Parameters: `per_page`, `prefix`, `delimiter`, `cursor` and `start_after`. |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->list('ACCOUNT_ID', 'BUCKET_NAME', [], 'JURISDICTION');
Get
Retrieve an object from a bucket.
The response carries the object itself, not a JSON envelope, so read it
with body() rather than json(). Object metadata comes back as
response headers, reachable through toPsrResponse().
$object = $client->r2()->objects()->get('ACCOUNT_ID', 'my-bucket', 'path/to/file.txt');
file_put_contents('file.txt', $object->body());
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
objectKey | string | Yes | Key of the object, e.g. `path/to/file.txt`. | |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->get('ACCOUNT_ID', 'BUCKET_NAME', 'OBJECT_KEY', 'JURISDICTION');
Upload
Upload an object to a bucket.
The object is sent as the raw request body, up to 300 MB. Anything larger needs R2's S3-compatible API and its multipart upload.
$client->r2()->objects()->upload(
'ACCOUNT_ID',
'my-bucket',
'path/to/file.txt',
file_get_contents('file.txt'),
'text/plain'
);
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
objectKey | string | Yes | Key to store the object under, e.g. `path/to/file.txt`. | |
contents | string | Yes | The object itself. | |
contentType | string | No | 'application/octet-stream' | Media type of the object. |
storageClass | string|null | No | Storage class to store the object as, e.g. `Standard` or `InfrequentAccess`. Defaults to the bucket's own. | |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->upload('ACCOUNT_ID', 'BUCKET_NAME', 'OBJECT_KEY', 'CONTENTS', 'CONTENT_TYPE', 'STORAGE_CLASS', 'JURISDICTION');
Delete
Delete a single object from a bucket.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
objectKey | string | Yes | Key of the object to delete. | |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->delete('ACCOUNT_ID', 'BUCKET_NAME', 'OBJECT_KEY', 'JURISDICTION');
Delete Many
Delete a list of objects from a bucket.
Every key given is deleted, and Cloudflare reports failures per key in the response rather than failing the whole request.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
objectKeys | array | Yes | Keys of the objects to delete. | |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->deleteMany('ACCOUNT_ID', 'BUCKET_NAME', [], 'JURISDICTION');
Delete By Prefix
Delete every object whose key begins with a prefix.
Cloudflare answers with a job descriptor rather than doing the work
inline: small jobs may come back already COMPLETED, larger ones keep
running in the background, so poll the id you get back with
$client->r2()->jobs()->get(). Objects written after the job starts are
not included in it.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
prefix | string | Yes | Key prefix to delete under. Pass an empty string to delete every object — or use `emptyBucket()`, which says so plainly. | |
dataCatalogCheck | bool | No | false | Refuse the request with a `409` if R2 Data Catalog is enabled on the bucket. |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->deleteByPrefix('ACCOUNT_ID', 'BUCKET_NAME', 'PREFIX', true, 'JURISDICTION');
Empty Bucket
Delete every object in a bucket.
The same operation as deleteByPrefix() with an empty prefix, and it
behaves the same way: you get a job descriptor back to poll with
$client->r2()->jobs()->get().
Cloudflare refuses to empty a bucket that has event notifications
configured, answering 409 with error code 10034 — remove the
notification rules first. Abort any active multipart uploads before
submitting, and avoid writing to the bucket while the job runs.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
bucketName | string | Yes | Bucket Name. | |
dataCatalogCheck | bool | No | false | Refuse the request with a `409` if R2 Data Catalog is enabled on the bucket. |
jurisdiction | string|null | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |
$response = $client->r2()->objects()->emptyBucket('ACCOUNT_ID', 'BUCKET_NAME', true, 'JURISDICTION');

