Unable to delete R2 object

Sorry for crossposting here and on Discord…

I’m using the excellent Microfeed repo (microfeed · GitHub ) to add objects to R2. Microfeed, which is intended as a publishing tool for individual podcasters, does not include a way to delete objects and the author argues coherently against deletion, but my use case is different. I’m allowing users of my app to upload some large objects that they may want to delete.

So I installed Wrangler and somehow got the authentication to work, and was able to issue a command to delete an object which looks as if it worked.

At the command line I did:
npx wrangler r2 object delete /production/media/audio-80ee6537b2e41406f6889f5bf3c16bf0.mp3

and I got:

:partly_sunny: wrangler 3.18.0 (update available 3.22.4)

Deleting object “production/media/audio-80ee6537b2e41406f6889f5bf3c16bf0.mp3” from bucket “”.
Delete complete.

But that did not delete the object. Minutes later, I can still play that mp3 and it remains listed in my Cloudflare R2 dashboard.

What am I doing wrong?

Does it work if you delete the object through the dashboard? If so, then I’d recommend making an issue on Sign in to GitHub · GitHub, so the wrangler team can triage it.

So, deleting that audio through the dashboard resulted in the object being removed from the dashboard but still playable for now. Assuming that the object really is deleted, I guess that’s due to caching.

Then I upgraded to the latest Wrangler - the least I can do before filing a bug - and issued the same command. And I got “Deleting object “production/media/audio-80ee6537b2e41406f6889f5bf3c16bf0.mp3” from bucket “”.
Delete complete.” Again…

Ultimately, I want to include a delete object command in a Firebase cloud function, so that when a user deletes an item in our system, the object ID is placed in a Firebase location and acted upon by the cloud function. I could do that with Wrangler or any other type of command that gets the job done. Thanks!

If it doesn’t show in the dash, then probably caching, you can try deleting your zone’s cache to confirm.

For programmatic deletion, I’d recommend using the S3 API S3 · Cloudflare R2 docs You’d also be able to delete it from cache as well using the Cloudflare API

I set up a script with the S3 API and got a similar result:

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: undefined,
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Deleted: [
    {
      Key: '/production/media/document-075f14634234790a4f9f813c291b0d80'
    }
  ]
}

But the object is not deleted.

There’s another person with this issue; R2 delete objects command does not delete objects

and here’s another: Not able to delete mp4 file in R2

Are you on a plan in which you are able to support tickets? If not, then I can raise this for you.

Thanks for the offer @Cyb3r-Jak3! I’m on a Pro plan - no live chat but tickets, yes. So I’ll ask an agent for help. Still, this looks more and more like a bug…

It does look like a bug, hence the support ticket. Once you make the ticket, then I can escalate it.

1 Like

Hi @Cyb3r-Jak3, I opened a support ticket - it’s #3107471.
Anything extra help would be much appreciated!
Let’s get to the bottom of this…

Here’s something interesting!

A screencast shows the author deleting an object - “test-image.webp” - and it appears to work. The object is no longer shown in the dashboard.
:thinking:
So I uploaded an image called test-image.webp, and yes, I was able to delete it…

Emboldened, I uploaded c09f966d-abd3-46ac-bd77-b9303f004dce.webp. It too could be deleted!

But my other objects including document-00ff8a128cfbfea42a6f14f3f686f489 (a pdf) or video-000ba0b7e7dcbc94f169f9df49876a29 (an mp4), no.

@Cyb3r-Jak3

I’ve escalated your ticket.

1 Like

Thanks for the help getting attention to my ticket.

Cloudflare agent Micky K. has put their finger on two bugs but they (the bugs, not Micky) are not yet squashed!

One is that R2 incorrectly reports that an object has been deleted when the deletion has not taken place.

And Micky found the root cause of the non-deletion, that I will quote here for the benefit of any other R2 users experiencing this issue until a fix has been implemented:

Taking a look at the command you sent over, I tried reproducing the error with the new information and I noticed that the wrangler command you ran did not include the file extension of the object (mp4). When I was testing the issue, one small thing I noticed is that when you upload files to R2, even if the file name does not have the extension included, Cloudflare will automatically add the file extension to the file name. So if you uploaded the mp4 file with the name video-000ba0b7e7dcbc94f169f9df49876a29, this would now have the name video-000ba0b7e7dcbc94f169f9df49876a29.mp4 on Cloudflare R2.

Thus, if you ran
npx wrangler r2 object delete <bucket-name>/production/media/video-000ba0b7e7dcbc94f169f9df49876a29
instead of
npx wrangler r2 object delete <bucket-name>/production/media/video-000ba0b7e7dcbc94f169f9df49876a29.mp4
the object is not deleted since it is not getting targeted correctly. If you run the wrangler/S3 command with the file name extension included, I expect you to be able to delete the file successfully, regardless of the file type.

So Cloudflare is adding the extension but not reporting it in the API response or showing it on the dashboard.

My problem is further complicated by the fact that I am adding objects via a 3rd-party program that doesn’t know about this bug.

This whole issue is based on a mistake on my part. I accidentally named both my bucket and its topmost object with the same name. When I tried deleting an object in that bucket, for example

npx wrangler r2 object delete <bucket-name>/production/media/video-000ba0b7e7dcbc94f169f9df49876a29

it wasn’t deleted because the correct command in this case would be

npx wrangler r2 object delete <bucket-name>/<object-name-same-as-bucket-name>/production/media/video-000ba0b7e7dcbc94f169f9df49876a29

My bad :slightly_frowning_face: but anyway…