0

I am currently having an issue when uploading files bigger then 10mb. I am uploading them to an s3 bucket.

I have tried to set the limit within the skipper that gets built in the middleware with the bodyparser.

order: [
  'cookieParser',
  'session',
  'myRequestLogger',
  'bodyParser',
  'compress',
  'poweredBy',
  'router',
  'www',
  'favicon',
],

myRequestLogger: function (req, res, next) {
  sails.log("Requested :: ", req.method, req.url);
  return next();
},

/***************************************************************************
 *                                                                          *
 * The body parser that will handle incoming multipart HTTP requests.       *
 *                                                                          *
 * https://sailsjs.com/config/http#?customizing-the-body-parser             *
 *                                                                          *
 ***************************************************************************/

bodyParser: (function _configureBodyParser() {
  var skipper = require('skipper');
  var middlewareFn = skipper({
    strict: true,
    limit: '50mb'
  });
  return middlewareFn;
})(),

This doesn't seem to be using the limit property being set at all.

Any advice on this would help.

1 Answers1

1

I'm not entirely sure where you found the limit option for Skipper, but limiting the file size of an upload is kinda documented between skipper-s3 the skipper.

Specifying the maxBytes option when receiving the upload in your action/controller should work.

If you're going to be uploading files to multiple actions/controllers then I'd keep the max file size somewhere like sails.config.custom.maxUploadFilesize so there's a single place to configure it - couldn't find any global Skipper options but I could have missed it.

const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;

req.file('avatar')
.upload({
  // Required
  adapter: require('skipper-s3'),
  key: 'thekyehthethaeiaghadkthtekey',
  secret: 'AB2g1939eaGAdesoccertournament',
  bucket: 'my_stuff',
  maxBytes: MAX_UPLOAD_BYTES
}, function whenDone(err, uploadedFiles) {
  if (err) {
    return res.serverError(err);
  }
  return res.ok({
    files: uploadedFiles,
    textParams: req.params.all()
  });
});
nahanil
  • 522
  • 3
  • 9
  • Hi nahanil, this throws a payload(413) error before it even gets to the controller itself from what I can see. The issue is not so much the upload itself but more so to get the file to that point as sails js blocks it. I have tried doing the following as this is a common problem: [link](https://stackoverflow.com/questions/28460135/sails-js-bodyparser-request-entity-too-large-on-version-0-10-5). But sadly all those solutions are for sails js versions before v1.0. – Dylan Welgemoed Apr 16 '19 at 19:05
  • @DylanWelgemoed I misinterpreted the initial problem - my bad! I'm not sure if it would have something to do with how you're sending the upload. [skipper.js#L35](https://github.com/balderdashy/skipper/blob/master/lib/skipper.js#L35) & [multipart.js](https://github.com/balderdashy/skipper/blob/master/lib/private/multipart.js) don't seem to do anything with the `limit` option provided your upload form's [enctype](https://stackoverflow.com/questions/1342506/why-is-form-enctype-multipart-form-data-required-when-uploading-a-file) is`multipart/form-data`. – nahanil Apr 17 '19 at 16:13
  • @DylanWelgemoed I just woke up wondering if the POST request is making it to your sails app **at all**. Do you have something like nginx/Apache/some other proxy sitting in front of your app? – nahanil Apr 18 '19 at 06:46