Can't upload to S3 (Cloudflare R2)

I was setting up R2 on my site following some guides here but no I just see a generic Sorry, but your upload failed. Please try again. message when I try to upload a file. The only thing I see in the logs are this:

I have my URLs configured in the app.yml file because the web UI was rejecting my URLs as structured in the how-to posts (invalid format):

image
The CDN_URL is the custom domain (as set in Cloudflare) and the S3_ENDPOINT is the URL in the web panel. I have all of my options configured properly with correctly created auth tokens:

It looks like Cloudflare is seeing some requests but nothing is being stored.

What is the problem?

Hey,

Is it not because of the final slashs (/) in the s3 cdn url and the s3 endpoint?

are these the guides you followed? are you certain your upload bucket is named “discourse”?

yea if you remove the ending slashes you should be able to use those URLs in the UI settings.

Yes, the first one is what I followed

Correct

I’ll try removing the slashes and will follow up

I removed the trailing slashes, still no luck. Same Unauthorized error.

Token is configured properly too

are you certain the cloudflare R2 token has read/write permission and did you correctly configure the CORS policy? i know you have a bit of a unique server configuration, and the cloudflare bucket permissions and configuration need to be exactly correct or it will throw permissions errors.

you created the wrong token type - you have a general API token. you need to create an R2 bucket token:

  1. go to the cloudflare dashboard → R2 object storage (left sidebar under storage & databases).
  2. on the right side of the R2 overview page, click manage (API tokens).
  3. click create account API token.
  4. fill in an appropriate token name and set Permissions to object read & write then save
  5. this will output an access key id and a secret access key. those are what you need to put into discourse’s S3 configuration

and yes you need to remove trailing slashes because discourse will likely reject them

Thanks, turns out that was the problem.. needlessly confusing but that’s Cloudflare’s fault

yea the cloudflare dashboard can be a hornet’s nest of configuration lol. glad you got it fixed!