Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multer middleware not working #25

Open
Svenskunganka opened this issue Sep 28, 2015 · 9 comments
Open

Multer middleware not working #25

Svenskunganka opened this issue Sep 28, 2015 · 9 comments

Comments

@Svenskunganka
Copy link

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.

@karlpokus
Copy link

Has this been fixed? I'm gonna need Multer as well for a task.

@Svenskunganka
Copy link
Author

Hey @karlpokus, I decided to add my own implementation using the binary EJSON datatype and transfer over the DDP connection instead. Ended up with a faster transfer as the initial connection was already established since the beginning.

@karlpokus
Copy link

@Svenskunganka Sounds cool. I'm gonna need to parse an e-mail with .csv attached so DDP is not an option for me.

@karlpokus
Copy link

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

@Taakn
Copy link

Taakn commented Aug 8, 2016

@karlpokus thanks for coming back and writing down your solution, you save the day! upload.single()wasn't working but upload.any() is!

@karlpokus
Copy link

@Taakn Happy to help.

@ghost
Copy link

ghost commented Sep 27, 2016

I'm unable to get multer working with Picker either. I've tried multiple variations. This was working at one point. Prior to Meteor 1.3 maybe? Is this still a know and open issue?

@karlpokus
Copy link

@ccuilla It's open alright. Can't remember what meteor version I was running. Sorry.

@anasalaqeel
Copy link

anasalaqeel commented Dec 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants