Reputation: 205
I'm writing a file up-loader in node.js, I've followed the documentation and while working on my mac the files have been uploading sometimes. On my windows pc files wont upload at all.
I'm using the express framework, and the app is hosted on an external server. The error im getting while trying to upload is:
Error: unintialized parser
at IncomingForm.write (/srv/node/test-app/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:130:17)
at IncomingMessage.<anonymous> (/srv/node/test-app/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:87:12)
at IncomingMessage.EventEmitter.emit (events.js:95:17)
at IncomingMessage.<anonymous> (_stream_readable.js:720:14)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at emitDataEvents (_stream_readable.js:745:10)
at IncomingMessage.Readable.on (_stream_readable.js:666:5)
at IncomingForm.parse (/srv/node/test-app/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:86:6)
at /srv/node/frog-jam/node_modules/express/node_modules/connect/lib/middleware/multipart.js:125:12
at noop (/srv/node/frog-jam/node_modules/express/node_modules/connect/lib/middleware/multipart.js:22:3)
Im posting the image through a form and on the server side I have this code handling the file upload:
fs.rename(req.files.image.path
, '/path/to/new/folder/' + req.files.image.name
, function(err) {
if(err) return res.json(err);
return res.json({message:'Upload complete'});
}
);
I have added console logs in and around this method but it seems like it is not getting to the controller method. I don't have any middle-ware to handle file uploads myself, and there isn't any more middle-ware on this route.
All the upload destinations are also correct as it will occasionally work on my mac book.
Upvotes: 2
Views: 1222
Reputation: 714
Probably you've updated Node.js to one of the latest versions (> 0.10.5 ). Express.js has old version of connect in its dependencies, which, in turn, has old version of formidable (plugin responsible for file uploads). To fix this issue:
$ cd <project_root>/node_modules/express/node_modules/connect
$ npm install formidable@latest
After that you should be good
Upvotes: 4