Upload file to server using W3C File API
This code shows how to upload file from file system using W3C File API and XMLHttpRequest.
//html
<input type="file" id="fileToUpload" onchange="uploadFile();" />
//js
function uploadFile() {
var fileForUpload = document.getElementById('fileToUpload').files[0];
var dataForUpload = new FormData();
dataForUpload.append("your properties")
dataForUpload.append("file_data", fileForUpload);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function(evt) {
... // success callback
}, false);
xhr.open("POST", "...");
xhr.send(dataForUpload);
}