-
-
Save conquext/017e746efc49216325f3e64da7f4c890 to your computer and use it in GitHub Desktop.
File upload using XHR PUT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var $dropTarget = $("#drop-target"); | |
var slice = Function.prototype.call.bind(Array.prototype.slice); | |
$dropTarget.on({ | |
drop: function (event) { | |
slice(event.originalEvent.dataTransfer.files).forEach(putFile); | |
return false; | |
}, | |
dragover: false | |
}); | |
function putFile(file) { | |
var xhr = new XMLHttpRequest(); | |
xhr.upload.addEventListener("progress", function (e) { | |
if (e.lengthComputable) { | |
console.log(e.loaded / e.total); | |
} | |
}); | |
xhr.upload.addEventListener("load", function () { | |
console.log("uploaded"); | |
}); | |
xhr.open("PUT", "http://localhost:7070/123/fromXHR.pdf"); | |
xhr.overrideMimeType(file.type); | |
xhr.send(file); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment