using AWS4fetch to generate presigned url

3 Replies
Varich
VarichOP2y ago
It give an url that look correct. However, when I try to upload to the given url, I got SignatureDoesNotMatch error message
kian
kian2y ago
X-Amz-Expires shouldn’t go in headers
Ahmed Eid
Ahmed Eid3mo ago
did you figure this out ? @Varich @kian are there any exmaples of how to acheive this with aws4fetch ?
const R2_URL = `https://${ctx.env.ACCOUNT_ID}.r2.cloudflarestorage.com`

const client = new AwsClient({
accessKeyId: ctx.env.ACCESS_KEY_ID,
secretAccessKey: ctx.env.ACCESS_KEY,
region: "auto",
service: "s3",
})

const key = `${app.slug}/${input.name}`

const url = `${R2_URL}/${ctx.env.BUCKET_NAME}/${key}`
const signedUrl = await client.sign(
new Request(url, { method: "PUT" }), //
{ aws: { signQuery: true } },
)
const R2_URL = `https://${ctx.env.ACCOUNT_ID}.r2.cloudflarestorage.com`

const client = new AwsClient({
accessKeyId: ctx.env.ACCESS_KEY_ID,
secretAccessKey: ctx.env.ACCESS_KEY,
region: "auto",
service: "s3",
})

const key = `${app.slug}/${input.name}`

const url = `${R2_URL}/${ctx.env.BUCKET_NAME}/${key}`
const signedUrl = await client.sign(
new Request(url, { method: "PUT" }), //
{ aws: { signQuery: true } },
)
this worked for me

Did you find this page helpful?