Generate signed URL for R2 from Cloudflare worker

Hello everyone, I am trying to replicate the result from this guide: https://developers.cloudflare.com/r2/data-access/s3-api/presigned-urls/ However, with the exact same code, the signedUrl variable return empty object({}). If anyone have any insight would be much appreciated! According to my understanding and written in the docs, I don't have to pass any accessKeyId or secretAccessKey. However, the s3 url that I got my cloudflare dashboard is : https://.<ACCOUNT ID>.r2.cloudflarestorage.com/<DROPBOX BUCKET>, which is different from the docs.
Presigned URLs · Cloudflare R2 docs
Presigned URLs are an S3 concept for sharing direct access to your bucket without revealing your token secret. A presigned URL authorizes anyone with the URL to …
5 Replies
kian
kian2y ago
You need to pass credentials otherwise you can’t sign the request, and that URL seems fine - other than the dot at the very start.
Varich
VarichOP2y ago
I have tried passing the credential, but still got the empty object back.
kian
kian2y ago
Seems like you're trying to return a Request object as JSON All you want is the url property I'd assume
Varich
VarichOP2y ago
Ohhh that's it. thank you so much I tried to console.log(JSON.stringify(obj, null, 4)) before and got empty object, so I though that object doesn't contains anything
kian
kian2y ago
Objects like Request/Response don't log/stringify well after a certain compatibility date
Want results from more Discord servers?
Add your server