Please note before everything I'd like to mention I'm very new in mean stack. I got multiparty working in my code however the uploaded image is significantly smaller than original. Here is what I have in my controller and I appreciate if anyone can point me to the right direction. I'm guessing I'm not reading the stream completely and somehow I drop out:
var multiparty = require('multiparty'), fs = require('fs');
exports.postImage = function(req, res) {
var form = new multiparty.Form();
var data = "";
var fname = "";
form.on('part', function(part) {
if (part.filename)
{
fname = '/Users/guest/Desktop/'+part.filename
var writeStream = fs.createWriteStream(fname);
part.pipe(writeStream);
}
else
{
form.handlePart(part);
}
});
form.on('close', function()
{
console.log("Form closes ...");
});
form.parse(req);
I also noticed when the upload is done meaning when I get my message "Form closes ..." after a minute or so the following error is thrown:
events.js:72
throw er; // Unhandled 'error' event
^
Error: Request aborted
at IncomingMessage.onReqAborted (/Users/guest/Desktop/wg-mean/node_modules/multiparty/index.js:183:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:465:12)
我发现了客户端的问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.