I\'m trying to build a file uploader with the native FileAPI in JavaScript and I want to upload the files via XMLHttpRequest (without jQuery) to a Node.js server, which uses
Thx to @Pengtuzi I solved it:
I used the FormData API to upload the files. My mistake was that I thought the error would happen on the server.
Here's the code that solved it for me:
function uploadFiles(files) {
var xhr = new XMLHttpRequest();
var formData = new FormData();
xhr.onload = successfullyUploaded;
xhr.open("POST", "http://localhost:3000/upload", true);
xhr.setRequestHeader('X-Requested-With','XMLHttpRequest');
for(var file in files) {
formData.append("uploads", files[file].data);
}
xhr.send(formData);
}