Upload Object
client.R2.Buckets.Objects.Upload(ctx, bucketName, objectKey, body, params) (*BucketObjectUploadResponse, error)
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
package main
import (
"bytes"
"context"
"fmt"
"io"
"github.com/stainless-sdks/cloudflare-go"
"github.com/stainless-sdks/cloudflare-go/option"
"github.com/stainless-sdks/cloudflare-go/r2"
)
func main() {
client := cloudflare.NewClient(
option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
)
response, err := client.R2.Buckets.Objects.Upload(
context.TODO(),
"example-bucket",
"path/to/my-object.txt",
io.Reader(bytes.NewBuffer([]byte("Example data"))),
r2.BucketObjectUploadParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", 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
}