minio-js
minio-js copied to clipboard
Set max file size for `presignedPutObject`
How can I make sure a file larger than 10 MB isn't uploaded to a presigned PUT request?
I don't see any options to do that with the presignedPutObject method.
Not sure if i understand the requirement fully.
may you Please have a look at : https://github.com/minio/minio-js/blob/06e408198fb9000406cc5b2facb50a3276f81df1/src/test/functional/functional-tests.js#L986
I'm using the presignedPutObject method to generate a presigned URL on which the user can directly upload the file.
It seems presignedPostPolicy method is a totally different topic!
I'm using the presignedPutObject method to generate a presigned URL on which the user can directly upload the file.
AFAIK, limiting upload objects with PUT is not possible in S3 spec. You will need to use POST instead.
Thank you for the info @vadmeste
So I tried to switch to a POST presigned URL instead:
On my server:
const tenMB = 10485760
const urlExpiry = 120 //seconds
const presignedUrl = await client.presignedUrl(
'POST',
process.env.S3_BUCKET,
filePath,
urlExpiry,
{
Conditions: ['content-length-range', 0, tenMB],
}
)
Then calling this URL on my client:
const file = e.target.files[0]
const formData = new FormData()
formData.append('file', file)
await sendRequest({
url: presignedUrl,
method: 'POST',
body: formData,
})
It fails with a BadRequest code.
I couldn't find any doc about the presignedUrl method. What am I missing?
Conditions: ['content-length-range', 0, tenMB], is part of preSignedPostPolicy so it needs to be set via postPolicy