Request entity too large when upload file using Nodejs api on AWS s3

Viewed 302

I find many solution on stackoverflow but still getting error In some device When i upload more than 2 image on multipart in node.js api then getting this error "Request entity too large"

I use AWS elasticbeanstalk with S3 service as backend server

Already use that express.json({limit: '50mb'}) but still getting that error,
Here is my code:

app.js

const app = express()
app.engine('html', require('ejs').renderFile)
app.set('view engine', 'html')

app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({
  limit: '50mb', 
  extended: true, 
  parameterLimit: 50000
}));

AwsImageuploader.js

async function uploadFile(filename,filepath){
    const fileStream = fs.createReadStream(filepath);

    const uploadParams = {
        Bucket: "bucker name",
        Body: fileStream,
        Key:filename
    }

    return s3.upload(uploadParams).promise()
}
1 Answers

You probably need to increase the limit in your .nginx config on ElasticBeanstalk, e.g.:

server {
...
   client_max_body_size 50mb;
....
}

You can check this article, which explains in further detail.

Related