I have an FTP portal built on node.js. When uploading a file over 100MB, i get an error.

Here is the error output:

{"error":{"message":"Request Entity Too Large","stack":"Error: Request         Entity Too Large\n 
at Object.exports.error (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/utils.js:62:13)\n
at limit (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/limit.js:46:47)\n
at multipart (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/multipart.js:97:5)\n
at /home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:57:9\n 
at urlencoded (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:52:72)\n 
at /home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:55:7\n 
at json (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/json.js:46:55)\n at Object.bodyParser [as handle] (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:53:5)\n 
at next (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/proto.js:190:15)\n 
at Object.cookieParser [as handle] (/home/ubuntu/sasite-ftp/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5)","status":413}}

I looked inside connect/lib/middleware/limit.js at lines 46 and 47:

     if (len && len > bytes) return next(utils.error(413));

Which seems to be related to this function in limit.js:

module.exports = function limit(bytes){
if ('string' == typeof bytes) bytes = utils.parseBytes(bytes);
if ('number' != typeof bytes) throw new Error('limit() bytes required');
return function limit(req, res, next){
var received = 0
  , len = req.headers['content-length']
    ? parseInt(req.headers['content-length'], 10)
    : null;

I can post some more code if need be, however you can easily lookup the code for connect in node_modules/express/node_modules/connect/

If anyone has any input on what the maximum file size actually is, and what the restrictions on it are, it would be much appreciated.

EDIT: the max file size is 100MB, in what file do I enter the code to change this as per the first the answer below's suggestion.

有帮助吗?

解决方案

Assuming you're using the Connect multipart middleware one way or another, the default maximum upload file size is 100MB, as defined here:

var limit = _limit(options.limit || '100mb');

If you want to set your own file upload limit, the multipart middleware has a limit option you can set:

app.use(connect.multipart({
  limit: '1000mb'
}));

If you are using connect.bodyParser(), it also uses the multipart middleware internally so the option can be specified the same way:

app.use(connect.bodyParser({
  limit: '1000mb'
}));

其他提示

From the connect-multiparty Express Middleware connect-multipart/index.js:

  • The options passed are merged with multiparty's Form object, allowing you to configure the upload directory, size limits, etc. For example if you wish to change the upload dir do the following.

So according to Multiparty Docs:

  • maxFieldsSize - Limits the amount of memory all fields (not files) can allocate in bytes. If this value is exceeded, an error event is emitted. The default size is 2MB.

I got mine working with:

var app = express(),
    multipart = require('connect-multiparty');

app.use(multipart({
    maxFieldsSize: '20MB'
}));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top