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.

Multer middleware not working

See original GitHub issue

I have an issue trying to implement a binary upload route using multer as a middleware.

Here’s my current code:

Meteor.startup(function() {
  var multer = Meteor.npmRequire('multer');
  var upload = multer({ storage: multer.memoryStorage() });
  Picker
    .filter(function(req, res) {
      return req.method === 'POST';
    })
    .route('/upload', function(params, req, res, next) {
      console.log(req.file);
      res.end();
    })
    .middleware(upload.single('excel'));
});

And the output of that console.log(req.file) is undefined. I’ve also logged the whole req object and cannot file any file property in it.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9

github_iconTop GitHub Comments

4reactions
karlpokuscommented, Feb 11, 2016

Hi @Svenskunganka I actually solved this I think. This works.

var multer = Meteor.npmRequire('multer'),
      upload = multer();

Picker.middleware(upload.any());

Picker.route('/incoming', function(params, req, res, next) {
    if (req.files && req.files.length > 0) {
      CSVParse(req.files[0].buffer, function(err, data){
        if (!err) {
          console.log(data);
        }
      });
    }
});
1reaction
anasalaqeelcommented, Sep 19, 2022

I had the same problem and there is no solution on the internet, so I tried to figure it out and finally I realised that the problem is from express-fileupload module if I use the multer before the line where I set the fileUpload middleware which is app.use(fileUpload()); it works fine and the multer middleware will be invoked without any problem, so I ended up to remove fileUpload module and everything works fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use Multer middleware - node.js - Stack Overflow
I am working on nodejs application i which i have to implement the upload files to AWS S3. I am trying to implement...
Read more >
Express multer middleware
Multer is a node.js middleware for handling multipart/form-data , which is primarily used ... NOTE: Multer will not process any form which is...
Read more >
Fix "Unexpected field" Error From Multer - Maxim Orlov
The foremost cause for this error is when the name attribute of the file input doesn't match the argument passed to one of...
Read more >
Multer: Easily upload files with Node.js and Express
Multer is a Node.js middleware for handling multipart/form-data that makes the ... the server, Node.js in our case, has less work to do....
Read more >
How to upload file using Multer in Express.js - Educative.io
Learn the 24 patterns to solve any coding interview question without getting lost in a maze of LeetCode-style practice problems. Practice your skills...
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