function uploadFile(file, url) { var reader = new FileReader(); reader.onload = function () { var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", function (e) { if (e.lengthComputable) { var progress = (e.loaded * 100) / e.total; } }, false); xhr.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { } else { } } }; xhr.open("POST", url); var boundary = "xxxxxxxxx"; xhr.setRequestHeader("Content-Type", "multipart/form-data, boundary=" + boundary); xhr.setRequestHeader("Cache-Control", "no-cache"); var body = "--" + boundary + "\r\n"; body += "Content-Disposition: form-data; name='myFile'; filename='" + file.name + "'\r\n"; body += "Content-Type: application/octet-stream\r\n\r\n"; body += reader.result + "\r\n"; body += "--" + boundary + "--"; if (xhr.sendAsBinary) { xhr.sendAsBinary(body); } else { xhr.send(body); } }; reader.readAsBinaryString(file); }