Created
March 20, 2012 17:13
-
-
Save domenic/2138293 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); | |
} | |
}()); |
This is a good snippet :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why when i try this I get a 405 (Method Not Allowed) error ?