Skip to content

It is possible to limit the file size when uploading using signed URL? #4743

Discussion options

You must be logged in to vote

Hi @jvitormelo, you can include the ContentLength parameter when generating the signed url as follow:
Note: The value for ContentLength is evaluated in bytes.

import {PutObjectCommand, S3Client} from "@aws-sdk/client-s3";
import {getSignedUrl} from "@aws-sdk/s3-request-presigner";

const client = new S3Client({
    region: 'us-east-2'
});
const body = "This is a test body";
const command = new PutObjectCommand({
    Bucket: process.env.TEST_BUCKET,
    Key: process.env.TEST_KEY,
    ContentLength: body.length
});
const signedUrl = await getSignedUrl(client, command);

fetch(signedUrl, {
    method: 'PUT',
    body: body
}).then(async (response) => {
    console.log('Status: ', response.st…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by yenfryherrerafeliz
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants