Using meteorhacks' Picker with middleware, and Npm


#1

Has anyone had any experience with using [picker][1] and [npm][2], and Multer as middleware?

After setting up meteorhacks:npm, I tried requiring multer inside the application like this var multer = Meteor.npmRequire('multer')

And using the module like this:

Picker.middleware(multer({
    dest: './fileUploads',
    limits: {
        fileSize: undefined
    },
    //more Multer set up
}));

The application builds, but when I try to navigate anywhere, I get the error:
TypeError: Object #<Multer> has no method 'call' at doCall (packages/meteorhacks:picker/lib/implementation.js:110:1)

Has anyone faced something similar? Or as anyone used Multer with Picker before?

Thank you beforehand.
[1]: https://github.com/meteorhacks/picker
[2]: https://github.com/meteorhacks/npm


#2

Hi, I used Multer on pure Node/Express. I guess you should rewrite code for the middleware as:

var multer = Meteor.npmRequire('multer');
Picker.middleware(multer({dest: '/fileUploads'}));
Picker.route('/fileUploads, 'function(params, req, res, next) {
   <...>
});

#3

I forgot to include that on the post, but my code already has that section

postPicker.route('/api/upload', function(params, req, res, next){

    if(done === true){
        console.log(req.files);
        done = false;
    }

    res.write("Ack!");
    res.end();
})

#4

Ah, I found the issue here. multer({}) doesnt return a function - it is a constructor. You should use multer.single() or multer.array() for middleware (see the docs), like

var multer = Meteor.npmRequire('multer');
var multerMid = multer({dest: './fileUploads'});
Picker.middleware(multerMid.array());

#5

Alright, I seem to be moving forward. It is not completely working, but at least it is better.

Which docs are you referencing?

In case you need to handle a text-only multipart form, you can use any of the multer methods (.single(), .array(), fields()).

The problem with this is that I am not planning to make a text only upload. Requests made to that endpoint are intended to bring files with it.