Upload Object
r2.buckets.objects.upload(strobject_key, objectbody, ObjectUploadParams**kwargs) -> ObjectUploadResponse
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key}
Uploads an object to an R2 bucket. The object body is provided as the request body. Returns metadata about the uploaded object.
The maximum upload size for this endpoint is 300 MB. 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:
Upload 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
)
response = client.r2.buckets.objects.upload(
object_key="path/to/my-object.txt",
body=b"Example data",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
bucket_name="example-bucket",
)
print(response.etag){
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
"string"
],
"result": {
"etag": "d41d8cd98f00b204e9800998ecf8427e",
"key": "path/to/my-object.txt",
"size": "1048576",
"storage_class": "Standard",
"uploaded": "2024-01-15T10:30:00Z",
"version": "3fd5b4a8-1234-5678-abcd-ef0123456789"
},
"success": true
}Returns Examples
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
"string"
],
"result": {
"etag": "d41d8cd98f00b204e9800998ecf8427e",
"key": "path/to/my-object.txt",
"size": "1048576",
"storage_class": "Standard",
"uploaded": "2024-01-15T10:30:00Z",
"version": "3fd5b4a8-1234-5678-abcd-ef0123456789"
},
"success": true
}