如何在 SailsJS v1.0 中设置 Skipper body Limit?

How do I set the Skipper body Limit in SailsJS v1.0?

我目前在上传大于 10mb 的文件时遇到问题。我正在将它们上传到 s3 存储桶。

我尝试在使用主体解析器在中间件中构建的船长内设置限制。

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;
})(),

这似乎根本没有使用设置的限制 属性。

对此的任何建议都会有所帮助。

我不完全确定您在哪里找到 Skipper 的 limit 选项,但限制上传文件大小的记录在 skipper-s3 the skipper.

之间

在 action/controller 中接收上传时指定 maxBytes 选项应该可行。

如果您要将文件上传到多个 actions/controllers,那么我会将最大文件大小保持在 sails.config.custom.maxUploadFilesize 之类的位置,因此只有一个地方可以配置它 - 找不到任何全局 Skipper 选项,但我可能会错过它。

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()
  });
});