Delete an object containing multiple folder and images inside in R2 bucket

For Workes & Pages, what is the name of the domain?

none

What is the issue or error you’re encountering

How can I delete an object inside cloudflare R2 bucket

What are the steps to reproduce the issue?

How can I delete an object containing folders and also that containing images, In the cloudflare dashboard we can’t delete it, I have to delete all images inside a folder. But I have 100’s of folders.
Is there any API to do this, can you provide a code for example I want to delete bucketname/objectname

Object storage doesn’t have folders. Those folders are are emulated by prepending the path to the filename.

If you want do large-scale deletes, you can use rclone, and it will do all the heavy lifting for you:

1 Like

I have correctly configured rclone but I cannot list my directories of bucket - using

C:\Users\divya>rclone config redacted
[onepiece]
type = s3
provider = Cloudflare
access_key_id = XXX
secret_access_key = XXX
region = auto
endpoint = https://191d76d3c1ca3e3afe728dbf94287133.r2.cloudflarestorage.com

C:\Users\divya>rclone lsd onepiece:
2024/08/03 23:26:00 ERROR : : error listing: AccessDenied: Access Denied
status code: 403, request id: , host id:
2024/08/03 23:26:00 Failed to lsd with 2 errors: last error was: AccessDenied: Access Denied
status code: 403, request id: , host id:

I have checked, my API tokens are active and has admin read and write access, still I am getting this error and I cant further download or delete objects.

That config looks right. The only thing that seems to be missing is acl = private, but that shouldn’t block your access.

And that endpoint corresponds with the account ID you see in the browser URL when visiting your bucket page?

Try with a -vv flag to get some debugging info.

If I corrupt my my key, I get a 401, not a 403.

Did you add “Client IP Address Filtering” when you created the key? That may be the issue. Leave it blank.

I created a new API token and using that access key and id, I was able to list the directories but old creadentials should have worked.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.