On my current page I use old file upload with input element. However, now I’ve implemented drag&drop from that very nice series of articles: http://www.sitepoint.com/html5-file-drag-and-drop/
There’s one snag. Before rewriting the page I was submitting the form with the file and server side service (Java’s appspot.com) did all the magic of retrieving the file, saving to DB etc. I would still like to take advantage of that service. However now, after rewriting the file upload to use XMLHttpRequest my code simply writes file to the content, whereas service expects form.
Is there a way to mimick miltipart/form-data form submission with XMLHttpRequest?
The
FormDataobject can be used to submitmultipart/form-dataforms.Basic example:
When strings are passed to the
.send()method of anXMLHttpRequestinstance, it is converted to unicode, then encoded as UTF-8. This means that a custommultipart/form-dataimplementation, using strings, will often not work correctly.