Skip to content
Start here

Delete Object

client.R2.Buckets.Objects.Delete(ctx, bucketName, objectKey, params) (*BucketObjectDeleteResponse, error)
DELETE/accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key}

Deletes an object from an R2 bucket.

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
Accepted Permissions (at least one required)
Workers R2 Storage Write
ParametersExpand Collapse
bucketName string

Name of the bucket.

maxLength64
minLength3
objectKey string

The key (name) of the object to delete. 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 BucketObjectDeleteParams
AccountID param.Field[string]

Path param: Account ID.

maxLength32
Jurisdiction param.Field[BucketObjectDeleteParamsCfR2Jurisdiction]Optional

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

const BucketObjectDeleteParamsCfR2JurisdictionDefault BucketObjectDeleteParamsCfR2Jurisdiction = "default"
const BucketObjectDeleteParamsCfR2JurisdictionEu BucketObjectDeleteParamsCfR2Jurisdiction = "eu"
const BucketObjectDeleteParamsCfR2JurisdictionFedramp BucketObjectDeleteParamsCfR2Jurisdiction = "fedramp"
ReturnsExpand Collapse
type BucketObjectDeleteResponse struct{…}

Result of a successful object deletion.

Key stringOptional

The key (name) of the deleted object.

Delete Object

package main

import (
  "context"
  "fmt"

  "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"),
  )
  object, err := client.R2.Buckets.Objects.Delete(
    context.TODO(),
    "example-bucket",
    "path/to/my-object.txt",
    r2.BucketObjectDeleteParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", object.Key)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "key": "path/to/my-object.txt"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "key": "path/to/my-object.txt"
  },
  "success": true
}