CORS :/

hi all - I had a function working yesterday to upload large files to a bucket. Come back today, and I'm getting CORS error. I've checked my CORS settings and my IP is included in the allowed, as well as the R2 API Token is a forever token. Any thoughts?
4 Replies
Sid
Sid3y ago
Hey, we haven’t released anything in a few days, this is surprising. Can you show me your CORS rules and the browser request you’re making?
Old Man Maker
Old Man MakerOP3y ago
Sorry Sid - I didn't see this sub message thing. Cool This is the CORS policy on the bucket: [ { "AllowedOrigins": [ "http://localhost:8081", "http://192.168.1.104:8081/", "http://192.168.1.100:8080/" ], "AllowedMethods": [ "GET", "PUT", "POST" ], "AllowedHeaders": [ "" ] } ] This is my S3Client call: const S3 = new S3Client({
region: "auto", endpoint: https://${CF_ACCOUNT_ID}.r2.cloudflarestorage.com, credentials: { accessKeyId: CF_ACCESS_KEY_ID, secretAccessKey: CF_ACCESS_KEY_SECRET, }, requestHandler: new XhrHttpHandler({}), // overrides default FetchHttpHandler in browsers. }); I'm using the Upload function in the S3 Lib for large files: const parallelUploads3 = new Upload({ client: S3, params: { Bucket: bucketName, Key: bucketKeyName, Body: largeFile }, tags: [ /
...*/ ], // optional tags queueSize: 4, // optional concurrency configuration partSize: (largeFile.size <= 5242880) ? 5242880 : largeFile.size * 2, // 1024 * 1024 * 10, // optional size of each part, in bytes, at least 5MB leavePartsOnError: false, // optional manually handle dropped parts });
Sid
Sid3y ago
Oh, so you're using the SDK from the browser? What would help is the HTTP request that goes out (from your bDevTools' Network tab), so I can check why your CORS doesn't seem to be applying Can you also try removing the trailing / from your origins?
Old Man Maker
Old Man MakerOP3y ago
Great pickup on the trailing slashes! That was it. Thank you so much.

Did you find this page helpful?