question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request pending if file limit exceed

See original GitHub issue

I use multer with single file variant.

var multer  = require('multer');

  var avatarMulter = multer({
    dest: './uploads/avatar',
    limits: {
      fieldNameSize: 100,
      fileSize: 1048576,
      files: 1,
      fields: 1
    }
  });

app.post('/api/photo', avatarMulter.single('file'), auth.requiresLogin, usersCustom.processAvatarImage);

Log:

Error: File too large
    at makeError (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\lib\make-error.js:12:13)
    at abortWithCode (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\lib\make-middleware.js:64:22)
    at FileStream.<anonymous> (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\lib\make-middleware.js:116:11)
    at FileStream.emit (events.js:104:17)
    at PartStream.onData (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\lib\types\multipart.js:212:18)
    at PartStream.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at PartStream.Readable.push (_stream_readable.js:126:10)
    at Dicer._oninfo (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\Dicer.js:192:36)
    at SBMH.<anonymous> (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\Dicer.js:127:10)
    at SBMH.emit (events.js:118:17)
    at SBMH._sbmh_feed (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\node_modules\dicer\node_modules\streamsearch\lib\sbmh.js:188:10)
   at SBMH.push (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\node_modules\dicer\node_modules\streamsearch\lib\sbmh.js:56:14)
    at Dicer._write (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\node_modules\dicer\lib\Dicer.js:109:17)
    at doWrite (_stream_writable.js:301:12)
    at writeOrBuffer (_stream_writable.js:288:5)
    at Dicer.Writable.write (_stream_writable.js:217:11)
    at Multipart.write (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\lib\types\multipart.js:282:24)
    at Busboy._write (C:\Users\Viktor\Develop\OnlineKonzultace\sources\onlinekonzultace\node_modules\multer\node_modules\busboy\lib\main.js:72:16)
    at doWrite (_stream_writable.js:301:12)
    at writeOrBuffer (_stream_writable.js:288:5)
    at Busboy.Writable.write (_stream_writable.js:217:11)
POST /api/photo 500 - - 74.112 ms

But express still processing request (rrequest is still pending from browser). Also invalid file is not deleted from /upload/avatar directory.

I try use checking err directly (below), but problem is same. My processing avatar function is never run after mutler CB. I also try remove everything except mutler callback and problem is still in.

multerInstance(req, res, function (err) {
      if (err) {
        console.log(err);
        return res.status(500).json({error: 'error'});
      }
      console.log('OK');
      res.json({});
    })

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
vmartiscommented, Jul 22, 2015

Here is complete code:

var express = require('express')
var multer  = require('multer')
var logger = require('morgan');
var upload = multer(
  { 
    dest: 'uploads/', 
    limits: {
       fields: 1,
       files: 1,
       fileSize: 512000
    }
  })

var app = express();

app.use(express.static('public'));
app.use(logger());

app.post('/avatar', upload.single('file'), function (req, res, next) {  
  res.end('finished');
})

app.use(function(err, req, res, next) {
  console.log('ERROR');
  res.status(500);
  res.end('');
  console.error(err.stack);
});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});
3reactions
sumedhm-iprogrammercommented, Feb 13, 2016

There is one work around which I have used in my current project

File: make-middleware.js change “function done(err)” at end of this function

Replace Line 52: onFinished(req, function () { next(err) })

With: Line 52: onFinished(req, function () { if( typeof err != "undefined" && err.code == 'LIMIT_FILE_SIZE') { req.fileSizeError = 1; next() } else next(err) })

And in app file you can change the code to

app.post('/upload', upload.single('upload'), function (req, res, next) {
    if(typeof req.fileSizeError != "undefined") {
        res.send({"error":"File too large"});// to display filesize error
    } else {
        res.send({"file":req.file}); // when file uploaded successfully
    }
}); 
Read more comments on GitHub >

github_iconTop Results From Across the Web

File Size Limit Exceeded Error Under Linux and Solution
I do have enough disk space to copy this file. I am getting an error “file size limit exceeded” under Linux. How do...
Read more >
e-Request - Outside Normal Processing Time
If you are a DACA renewal applicant please contact USCIS at (1-800) 375-5283 to inquire on a case pending longer than 105 days....
Read more >
Rate Limits - Let's Encrypt
Exceeding the Pending Authorizations limit is reported with the error message too many currently pending authorizations .
Read more >
Understanding Kubernetes Limits and Requests - Sysdig
Kubernetes defines Limits as the maximum amount of a resource to be used by a container. This means that the container can never...
Read more >
I'm experiencing a long response time - Postman
If the response size of your request exceeds 100MB, you can use the following workaround: try using the Send and Download option when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found