Report this

What is the reason for this report?

How to restrict file size with aws-sdk getSignedUrl

Posted on July 5, 2022

Hello, I’m using digital ocean to allow users to upload videos using signed urls. However i wanna make sure the the file is the file size it request to upload, and current after hours of searching for an answer i cannot find one.

So my question is, how can i prevent users to steal the signed url and upload a massive file?

PS: I’m using ‘@aws-sdk/s3-request-presigner’ with the function getSignedUrl() as the example from DO says



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

If you’re looking to limit the upload size of files using pre-signed URLs, you can achieve this by using content-length-range in the conditions of your pre-signed URL policy. Set a minimum and maximum file size range to restrict uploading of larger files.

Here’s an example:

  1. "conditions": [
  2. ["content-length-range", _minSize_, _maxSize_]
  3. ]

By replacing the minSize and maxSize values with your desired file size limits, you can prevent users from uploading files outside that size range.

For more details on how to control the size of the uploaded files, please refer to DigitalOcean Spaces Documentation: Handling File Uploads.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.