R2 custom metadata not being set

Hello everyone, I'm trying to add some metadata when uploading images to R2 via signed url. Here's the snippet:
const url = await getSignedUrl(
r2,
new PutObjectCommand({
Bucket: 'images',
Key: fileName,
ContentType: fileType,
Metadata: {
user: userId,
workspace: workspaceId,
}
}),
{ expiresIn: 60 }
)
const url = await getSignedUrl(
r2,
new PutObjectCommand({
Bucket: 'images',
Key: fileName,
ContentType: fileType,
Metadata: {
user: userId,
workspace: workspaceId,
}
}),
{ expiresIn: 60 }
)
When I go to the dashboard I see "no custom metadata set".
No description
5 Replies
Gian
Gian13mo ago
Update I tried adding the metadata headers manually to the PUT request to the signed URL and it works.
const upload = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': file.type,
'x-amz-meta-user': userId,
'x-amz-meta-workspace': workspaceId,
},
body: file,
})
return upload.ok
const upload = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': file.type,
'x-amz-meta-user': userId,
'x-amz-meta-workspace': workspaceId,
},
body: file,
})
return upload.ok
Is this intended behavior? What's the point of the Metadata parameter in the signed url?
lordbinbash
lordbinbash4mo ago
Same issue, did you find a solution to this?
sunspirit
sunspirit3mo ago
Same issue here
Hard@Work
Hard@Work3mo ago
If I'm understanding what you are saying here, signing it just means that R2 will accept a request with that metadata, not that it will apply that metadata automatically
sunspirit
sunspirit3mo ago
Thanks @Hard@Work | R2 - I think there's indeed a misunderstanding then. I guess the best way forward is to go for direct to worker upload, rather than via a signed url.
Want results from more Discord servers?
Add your server