Hi, how can i set custom headers when

Hi, how can i set custom headers when downloading a file via presigned url? I tried setting it like this:
async function generatePresignedUrl(objectKey, endpoint, bucket) {
const url = new URL(`${endpoint}/${bucket}/${objectKey}`)

url.searchParams.set('X-Amz-Expires', '3600')

const signed = await r2.sign(new Request(url, {
method: 'GET'
}), {
headers: {
'Content-Disposition': 'attachment; filename=' + objectKey
},
aws: {
signQuery: true
}
})

return signed.url
}
async function generatePresignedUrl(objectKey, endpoint, bucket) {
const url = new URL(`${endpoint}/${bucket}/${objectKey}`)

url.searchParams.set('X-Amz-Expires', '3600')

const signed = await r2.sign(new Request(url, {
method: 'GET'
}), {
headers: {
'Content-Disposition': 'attachment; filename=' + objectKey
},
aws: {
signQuery: true
}
})

return signed.url
}
But I keep getting Signature Mismatch errors. Can I set this via meta data when uploading a new file to r2? I need to set this somehow, because e.g. Chrome always changes the fileextension of a custom zip extension to .zip
1 Reply
𝖆𝖚𝖙𝖎𝖘𝖙
Solved it by providing the wanted header while uploading like this:
const params = {
Bucket: bucket.value,
Key: fileId.value,
ContentType: file.type,
ContentDisposition: 'attachment; filename=' + file.name,
Body: file,
};
const params = {
Bucket: bucket.value,
Key: fileId.value,
ContentType: file.type,
ContentDisposition: 'attachment; filename=' + file.name,
Body: file,
};
Want results from more Discord servers?
Add your server