File uploads using Node.js: once again
I’ve already wrote an article about file uploads in Node.js before. However Node.js is in rapid development and so many things have changed since then.
So, I decided to do an updated version, which accommodates for such changes:
eventsmodule was removedposixmodule was replaced byfs- various changes into HTTP request/response API
- multipart module refactored into separate project
- convenient
fs.createWriteStreaminstead of low-level API
See the code snippet under the cut, or on github. Special thanks goes to Felix Geisendörfer for some useful suggestions.
Please note that you’ll need to install multipart module for the code to work.
To make it clear, Node.js version used was v. 0.1.91.
UPD: Fixed stream.onData handler. It was writing corrupted data (UTF-8 character were translated) because of binary mode not being used. Thanks to Ron Ward for suggesting solution.
Read more...