Created
October 23, 2014 16:08
-
-
Save phillip-haydon/1bf930eebb8bbbc16faf to your computer and use it in GitHub Desktop.
Upload text file that does not exist
This file contains hidden or 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 button = document.getElementById("TestUpload"); | |
function setupRequest() { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', "/home/upload", true); | |
xhr.setRequestHeader("Accept", "application/json"); | |
return xhr; | |
} | |
button.addEventListener("click", function () { | |
var xhr = setupRequest(); | |
var formData = new FormData(); | |
var text = ['RAWRRRRRRRRRR']; | |
var file = new Blob(text, { type: 'plain/text' }); | |
formData.append("banana.txt", file); | |
xhr.send(formData); | |
}); | |
}()); |
This file contains hidden or 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
<button id="TestUpload">Test Upload</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment