Hi,
I am using multer and it works fine in the http object, here is the code:
server = http.createServer(function(req, res){
var upload = multer({ storage : multerhelper.storage}).single('userFile');
upload(req, res, function(err) {
if(err)
console.log("Error uploading the file");
});
});
The moment I take this piece of code outside of the http object inside another file, it doesn't work anymore.
handlers._users.post = function(req, res, data, callback){
var upload = multer({ storage : multerhelper.storage}).single('userFile');
upload(req, res, function(err) {
if(err)
console.log("Error uploading the file");
callback(400, {'Message' : 'Done'});
});
});
Your help is appreciated.
Could it be that the body is already consumed by another middleware? Without seeing any more of the code it's impossible for me to tell...
I would recommend posting general questions to Stack Overflow or another forum, where you are more likely to get help 鈽猴笍
Hi Linus,
It would make sense if the body of the request gets consumed, I was not aware of the possibility of such a thing. I thought passing the request as a parameter should keep it whole.
I will dig in that direction and ask on Stack Overflow if I have any further questions,
Thank you.
Yeah, the request body is a ReadableStream as an abstraction on top of the underlying socket, so you can only read from it once. This is done deliberately as to not keep the entire response in memory at any one time.
Good luck!
Interesting, thanks a lot for your generous contribution.