Skip to content
Cloudflare Docs

Delete objects

You can delete objects from R2 using the dashboard, Workers API, S3 API, or command-line tools.

Delete via dashboard

  1. In the Cloudflare dashboard, go to the R2 object storage page.

    Go to Overview
  2. Locate and select your bucket.

  3. Locate the object you want to delete. You can select multiple objects to delete at one time.

  4. Select your objects and select Delete.

  5. Confirm your choice by selecting Delete.

Delete via Workers API

Use R2 bindings in Workers to delete objects:

TypeScript
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
await env.MY_BUCKET.delete("image.png");
return new Response("Deleted");
},
} satisfies ExportedHandler<Env>;

For complete documentation, refer to Workers API.

Delete via S3 API

Use S3-compatible SDKs to delete objects. You'll need your account ID and R2 API token.

TypeScript
import { S3Client, DeleteObjectCommand } from "@aws-sdk/client-s3";
const S3 = new S3Client({
region: "auto", // Required by SDK but not used by R2
// Provide your Cloudflare account ID
endpoint: `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`,
// Retrieve your S3 API credentials for your R2 bucket via API tokens (see: https://developers.cloudflare.com/r2/api/tokens)
credentials: {
accessKeyId: '<ACCESS_KEY_ID>',
secretAccessKey: '<SECRET_ACCESS_KEY>',
},
});
await S3.send(
new DeleteObjectCommand({
Bucket: "my-bucket",
Key: "image.png",
}),
);

For complete S3 API documentation, refer to S3 API.

Delete via Wrangler

Use Wrangler to delete objects. Run the r2 object delete command:

Terminal window
wrangler r2 object delete test-bucket/image.png