I have written a script in JavaScript to handle a file drag and drop. When the 'drop' listen is called the file is captured using dataTransfer.files (function below).
event.preventDefault();
event.stopPropagation();
console.log(event.dataTransfer.files[0]);
uploadFiles = event.dataTransfer.files;
fileBoxUpLoad(uploadFiles);
Console log shows the file appears to be capture correctly
File {name: "Changi - 2016.pdf", lastModified: 1473382409845, lastModifiedDate: Fri Sep 09 2016 10:53:29 GMT+1000 (Australian Eastern Standard Time), webkitRelativePath: "", size: 197754, …}
The fileBoxUpLoad function is call and when the code gets to the xmlhttp.send it throws an error
Unexpected token o in JSON at position 1 at JSON.parse ()
var formData = new FormData();
for(var x=0; x<=item.length; x++)
{
formData.append('file', item[x]);
}
var xmlhttps = new XMLHttpRequest();
xmlhttps.open("POST", uri);
xmlhttps.setRequestHeader('Content-Type', file.type);
xmlhttps.send(formData);
I understand this means I am trying to parse an Javascript object, when I don't think I am and I can't see where my code is any different to all the tutorials I have read. Any advice? Thanks!!