Problem with settings CORS policies on R2

SOLUTION

Well, it turned out that my R2 access keys dad expired. Renewal of the keys solved my case.

I spent hours trying to figure out what’s going on with Cloudflare today. I just found out it was just a cache issue. After updating the CORS Policy, you must wait a few minutes to make requests to your files. If you made requests before updating your CORS policies, you will receive a CORS error until the cache is cleared.

1 Like

I am new to R2. I want to only allow abc.com origin. And then I set the Cors policy rule as follows:. but I can still access my file from anywhere. Please explain it to me. Thank you a lot.

[
  {
    "AllowedOrigins": [
      "https://abc.com"
    ],
    "AllowedMethods": [
      "GET"
    ]
  }
]

In case anyone else is facing this issue. I know it’s been frustrating. Try this steps

That solved the problem for me.

It was because the image was already loaded using tag in the browser (without CORS), and then now I tried to load it again using fetch, now it has cors. But the browser was trying to use the cache (the previous image without cors)

4 Likes

Setting CORS is so painful with Cloudflare. Last week I tried Backblaze. Needed to set up CORS too. Uploaded a simple cors json file and here you go, it worked right away.
With Cloudflare, I use a file to allow all origins and all headers (tried many variation) and it’s impossible for my web site (localhost, in development right now) to put an image in a bucket using a presigned url. So frustrating. Since Cloudflare has no ticket system for R2 to be helped, it is very frustrating and the net result may be that I won’t be able to use R2.

1 Like

Thank you so much

Thanks! This solved it. Should be a default.

Thanks man god bless you, finally solved it, that is really unintuitive behavior that should be highlighted in r2 docs