R2 CORS Issues

Perhaps my conenctions are completely screwed up as is. I can test everything against it but CORS gets int he way everytime regardless of allowed URLS, etc.
14 Replies
Hard@Work
Hard@Work4mo ago
@Jedeye do you have somewhere I can test? Also, can you share your CORS policy?
Jedeye
JedeyeOP4mo ago
I appreciate it, sure. { "CORSRules": [ { "AllowedOrigins": ["https://filmdevboard.netlify.app"], "AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"], "AllowedHeaders": ["*"], "ExposeHeaders": ["ETag"], "MaxAgeSeconds": 3000 } ] } And thank you. I have narrowed it down to CORS. I jsut did an R2 test with python and it completed successfully so I am 99% sure it is CORS related somwhere.
Hard@Work
Hard@Work4mo ago
Do you have a page somewhere that attempts to load a file from R2?
Jedeye
JedeyeOP4mo ago
Do you mean other than the allowed origin page? That's the origin.
Jedeye
JedeyeOP4mo ago
Jedeye
JedeyeOP4mo ago
I'm getting this error in the network console: https://11005b0e71c889b406a7ae554be84319.r2.cloudflarestorage.com/filmdevboard-files/data.json' from origin 'https://filmdevboard.netlify.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. which is weird because I have it in my CORS policy.
Hard@Work
Hard@Work4mo ago
And that policy is applied to filmdevboard-files, right? Are you handling the signature for the URL anywhere?
Jedeye
JedeyeOP4mo ago
No, just using basic auth. I'll try that. I've been trying to keep function calls to Netlify to a minimum but maybe I have been limiting it too much.
Hard@Work
Hard@Work4mo ago
Note too that the r2.cloudflarestorage.com endpoint always requires authentication. "Public Bucket" exposes your bucket over a subdomain on r2.dev(which does not require auth). This endpoint can be rate-limited however, so we recommend you do not use it for production traffic
Jedeye
JedeyeOP4mo ago
So am I actually doing something very wrong? What would be your recommended approach for this? BTW, I appreciate the help very much Currently workign on it. I'll let you know how it goes. I'm trying a different method that was 'suggested' to me and I'll see if that does it. If not I'll revert back to my other commit. I tihnk I found my problem. I'm reverting back to before AI. I think it is all based in my Netlify functions. Sorry to bother you.
gruntlord6
gruntlord64mo ago
I also believe you need the domain to point to r2, not sure if a netlify subdomain does that or not
Hard@Work
Hard@Work4mo ago
Not sure I understand this one?
gruntlord6
gruntlord64mo ago
I think I just read it wrong
Jedeye
JedeyeOP4mo ago
I actually have it working now. I used a timed proxy to access it and it seems to be functioning so far. At the very least I have the JSON settings files working so I think I am moving int he right direction and now jsut to get my binaries organized. But that's much easier compared to where I was, Binaries are now uploading properly. Thanks for the help @Hard@Work | R2

Did you find this page helpful?