fork download
  1. function uploadFile(file, url) {
  2.  
  3. var reader = new FileReader();
  4.  
  5. reader.onload = function () {
  6. var xhr = new XMLHttpRequest();
  7.  
  8. xhr.upload.addEventListener("progress", function (e) {
  9. if (e.lengthComputable) {
  10. var progress = (e.loaded * 100) / e.total;
  11. }
  12. }, false);
  13.  
  14. xhr.onreadystatechange = function () {
  15. if (this.readyState == 4) {
  16. if (this.status == 200) {
  17.  
  18. } else {
  19.  
  20. }
  21. }
  22. };
  23.  
  24. xhr.open("POST", url);
  25. var boundary = "xxxxxxxxx";
  26.  
  27. xhr.setRequestHeader("Content-Type", "multipart/form-data, boundary=" + boundary);
  28. xhr.setRequestHeader("Cache-Control", "no-cache");
  29.  
  30. var body = "--" + boundary + "\r\n";
  31. body += "Content-Disposition: form-data; name='myFile'; filename='" + file.name + "'\r\n";
  32. body += "Content-Type: application/octet-stream\r\n\r\n";
  33. body += reader.result + "\r\n";
  34. body += "--" + boundary + "--";
  35.  
  36. if (xhr.sendAsBinary) {
  37.  
  38. xhr.sendAsBinary(body);
  39. } else {
  40.  
  41. xhr.send(body);
  42. }
  43. };
  44.  
  45. reader.readAsBinaryString(file);
  46. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty