R2 REST APIS
Hello Team I need help. Im trying to upload a file using R2 REST APIS and not the SDK wrapper.... I have constructed the request headers and it matches my POSTMAN call (which works)... However on my browser the same endpoint returns a 403 for the prefilght OPTION request ... I have tried setting up CORS on R2 side of things but it doesn't allow the OPTION http method ...has anyone tried doing something like this
5 Replies
Are you using
api.cloudflare.com
or r2.cloudflarestorage.com
?here const url =
https://${accountid}.r2.cloudflarestorage.com/${r2bucket}/${objectKey}
;
@Erisa | Support EngineerWhats your CORS configuration in R2 side? OPTIONS should work if its configured correctly
At least, it does for presigned URLs afaik, I don't think its recommended to use the full S3 API in a browser
Since S3 will sign the method usually
[
{
"AllowedOrigins": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"HEAD"
],
"AllowedHeaders": [
"Content-Type"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3600
}
]
i saw this onlinee..when i try to add the OPTIONS method i get a squiggly line beneath it
@Erisa | Support Engineer
I cant use the SDK for my implementation .I want to directly call the APIS
isnt that possible
i tried using the POSTMAN Collection and it worked ...how do i achieve same in code
You need to use something to sign your requests with AWS SigV4, i.e aws4fetch
You can't just use the API token as-is