简体   繁体   English

增加帆身P

[英]Increase sails bodyP

In my app (sails 0.12.0) I want to extend a limit of bytes send upon POST request. 在我的应用程序(sails 0.12.0)中,我想扩展在POST请求时发送的字节数限制。 So I've followed the comments in this stackoverflow question 所以我遵循了这个stackoverflow问题中的评论

var skipper = require('skipper');
skipper.limit = 1024*1024*100;

middleware: {
    bodyParser: skipper
}

I still get an error: 我仍然收到错误消息:

 "data": {
    "code": "E_EXCEEDS_UPLOAD_LIMIT",
    "name": "Upload Error",
    "maxBytes": 15000000,
    "written": 15007474,
    "message": "Upload limit of 15000000 bytes exceeded (15007474 bytes written)"
  }

I've also tried to add the code below directly under module.exports.http and then I've tried to add it in the middleware only. 我还尝试将下面的代码直接添加到module.exports.http下,然后尝试仅将其添加到middleware

  bodyParser: (function () {
    var opts = {limit:'50mb'};
    var fn;

    // Default to built-in bodyParser:
    fn = require('skipper');
    return fn(opts);

  })

My question is: Why none of these codes work and how can I increase the limit. 我的问题是:为什么这些代码都不起作用,如何增加限制。 The solution can be not elegant. 解决方案可能不是很优雅。

Everything that you need - set 您需要的一切-设置

maxBytes maxBytes

attribute in object of options to upload() method of skipper Upstream. 跳线Upstream的upload()方法的选项对象中的属性。

req.file('image').upload({maxBytes: 50000000}, function (err, uploadedFiles) {
     if (err) return res.serverError(err.message);
     if(uploadedFiles.length > 0) {
     // do with uploaded images what you want
      .....
     }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM