Cannot put objects to my R2 bucket using a custom domain

I was able to configure a custom domain in order to access the files in my R2 bucket through that custom domain. However, when I try to upload a file using that custom domain, the process doesn’t work. However when I use the default endpoint from Cloudflare then the process for uploading files works properly.

Isn’t it allowed to upload files to R2 using custom domains?

I short, what I’m experiencing is that I can use a custom domain for reading files from my R2 bucket but not for uploading files there.

Thanks.

You have to use the r2.dev hostname for uploading with S3 API.

Or you can code a Worker, and assign that Worker a custom domain.

I’m totally new on all this about Cloudflare (just registered with them less than 24 hrs now) and I may be wrong about my understandings of the things so far. These are my concerns about the 2 things you mentioned above:

r2.dev

Under this section Cloudflare says the following:

When you enable r2.dev access, anyone on the Internet can use the public r2.dev URL to view objects in this bucket. However, usage is rate-limited and is not recommended for production.

Then I have 2 concerns here

  • I don’t want to make my bucket totally public (like out of control unconditionally public), I mean, I think some of the files in my bucket should be restricted.

  • They say this r2.dev is not recommended for production.

Workers

I don’t like too much the idea of placing code outside my project Git repository because I want to control all the changes I do in my project. So I prefer to keep all my code in a single place.

Could you please clarify a bit about all this to me?

Also if you know about any documentation that could help please post it here.

Thanks!

Sorry, I’ll have to correct my comment about the S3 API endpoint. It’s https://<ACCOUNT_ID>.r2.cloudflarestorage.com

That’s where your uploads go, unless you use the Workers approach.

This is expected behavior. Is there a reason you don’t want to use the S3 API endpoint for your uploads?

The reason is that I configured a custom domain for my CDN, e.g.: cdn.mydomain.com and that looks well related to my domain. It looks good when serving the content through that custom domain (actually subdomain). I would like to use same well-related subdomain for uploading files. That way when the users of the app have to upload a file, for example a picture, on the browser developer tool they could see that the request is done to my custom domain cdn: cdn.mydomain.com, and not to another domain they may not be familiar with on this case cloudflare’s domain (they not necessary have to know about cloudflare).

I don’t really understand why this is not possible out the box for the uploading files while the download works pretty well.

Any thoughts about this?

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