minio-js icon indicating copy to clipboard operation
minio-js copied to clipboard

Set max file size for `presignedPutObject`

Open baptisteArno opened this issue 3 years ago • 4 comments

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.

baptisteArno avatar Jun 08 '22 12:06 baptisteArno

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

prakashsvmx avatar Jun 08 '22 12:06 prakashsvmx

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!

baptisteArno avatar Jun 08 '22 12:06 baptisteArno

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.

vadmeste avatar Jun 08 '22 13:06 vadmeste

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?

baptisteArno avatar Jun 09 '22 07:06 baptisteArno

Conditions: ['content-length-range', 0, tenMB], is part of preSignedPostPolicy so it needs to be set via postPolicy

prakashsvmx avatar Aug 24 '22 12:08 prakashsvmx