This is the error I encountered HTTP content length exceeded 10485760 bytes while uploading to s3.
I’m trying to upload image and video. How do I upload image and video above greater than 10mb in size? The request won’t go above 10mb size because AWS API Gateway allows only Upto 10mb.
This is my code
const s3Client = new S3Client({
useAccelerateEndpoint: true,
region: region,
credentials: {
accessKeyId:access_key_id,
secretAccessKey: secret_key_id
},
});
const user_media_upload = multer({
storage: multerS3({
s3: s3Client,
bucket: bucket,
key: function (req, file, cb) {
const folderName = file.fieldname === 'image' ? 'media_images' : 'media_videos';
const fileName = `${file.fieldname}-${uuidv4()}-${file.originalname}`;
const key = `${folderName}/${fileName}`;
console.log("Uploading file to S3 with key:", key);
file.s3Key = key;
cb(null, key);
}
}),
limits: { fileSize: 100 * 1024 * 1024 } // 100 MB limit
});
const generatePresignedUrl = async (file) => {
if (!file || !file.s3Key) {
throw new Error('File object or S3 key is undefined');
}
const key = file.s3Key;
const command = new PutObjectCommand({
Bucket: bucket,
Key: key,
});
const url = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
return { key, url };
};
New contributor