Posting a binary file to the server
Posting text, XML, or JSON to the server is relatively easy, and most JavaScript libraries are optimized for that scenario.
Posting binary data is slightly trickier. Modern applications may need to be able to upload the generated binary files; examples include images drawn on an HTML5 canvas, ZIP files created with JSZip, and so on.
Additionally, it's convenient to be able to upload files selected using the HTML5 file API. We can do some interesting things with it, such as resumable file uploads by splitting the file into smaller parts and uploading every part separately to the server.
In this recipe, we're going to upload files selected by the user using a file input.
Getting ready
The server will be implemented using Node.js—you can download and install Node.js from http://nodejs.org/. The server will be implemented with the Node.js framework Connec t (http://www.senchalabs.org/connect/).
How to do it...
Let's write the client and server code.
Create a file...