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 has any insight would be much appreciated!
According to my understanding and as written in the docs, I don't have to pass any accessKeyId or secretAccessKey.
However, the s3 url that I got from my cloudflare dashboard is : https://<ACCOUNT ID>.r2.cloudflarestorage.com/<DROPBOX BUCKET>
, which is different from the docs.
const r2 = new AwsClient({
accessKeyId: "",
secretAccessKey: "",
service: "s3",
region: "auto",
});
app.get("/getUploadUrl", async (c) => {
const timeOut = +c.req.queries("timeOut") ?? 60 * 5;
const fileName = c.req.queries("fileName") ?? crypto.randomUUID();
const bucketName = c.req.header("bucket");
const bucketUrl = bucketNameToUrl[bucketName];
console.log("fileName", fileName);
const signedUrl = await r2.sign(
new Request(`${bucketUrl}/${fileName}`, {
method: "PUT",
}),
{
aws: { signQuery: true },
headers: {
"X-Amz-Expires": timeOut.toString(),
},
}
);
return c.json(signedUrl);
});