title: How to fix '413 Request Entity Too Large' error in Node.js
body: <p>I am attempting to allow users to upload several images to my website which will then get emailed to all users as attachments but I am coming across an error stating the file size is too large.</p>
  
  <p>I am using Mailgun to send the mail, Cloudinary to upload/store the images, MongoDB as my database, request.js to request the images, Cloud 9 to develop in, and Node.js/Express as my backend.</p>
  
  <p>The user process goes like this:</p>
  
  <ul>
  <li>User submits pictures onto the site</li>
  <li>Pictures are uploaded via Cloudinary and the direct link to each image is saved in the MongoDB database</li>
  <li>Mail goes out via Mailgun to inform users of the new post with the images added as attachments</li>
  </ul>
  
  <p>I am using request.js to request the images from Cloudinary and then pushing each image into an array which is then added as an attachment parameter for Mailgun.</p>
  
  <p>This works great for smaller images, but when a user uploads a larger batch of high-quality images I receive the error.</p>
  
  <p>I have tried adding a 100MB fileSize limit to Multer, bodyParser.json, and bodyParser.urlencoded as well as a parameterLimit of 100MB.</p>
  
  <pre><code>var upload = multer({ storage: storage, fileFilter: imageFilter, limits: {fileSize: 100000000}});
  
  app.use(bodyParser.json({limit: "100mb", parameterLimit: 100000000}));
  app.use(bodyParser.urlencoded({limit: '100mb', extended: true, parameterLimit: 100000000}));
  
  var images = [];
  post.images.forEach(function(photo){
      images.push(request(photo));
  });
  
  var data =  {
      from: "email &lt;email@email.com&gt;",
      to: "email@email.com",
      subject: 'this is an email',
      html: 'this is an email',
      attachment: images
  };
  </code></pre>
  
  <p>The expected results are a successful email being sent with all of the images attached.</p>
  
  <p>The actual result is this error message:</p>
  
  <pre><code>{ Error: &lt;html&gt;
  &lt;head&gt;&lt;title&gt;413 Request Entity Too Large&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;413 Request Entity Too Large&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  at IncomingMessage.res.on (/home/ubuntu/workspace/TW/node_modules/mailgun-js/lib/request.js:319:17)
  at emitNone (events.js:111:20)
  at IncomingMessage.emit (events.js:208:7)
  at endReadableNT (_stream_readable.js:1064:12)
  at _combinedTickCallback (internal/process/next_tick.js:138:11)
  at process._tickCallback (internal/process/next_tick.js:180:9) statusCode: 413 }
  </code></pre>