my website is running on localhost:8084 and I need to upload a file to localhost:8086. Below is the JavaScript code:
var xhr = new XMLHttpRequest();
xhr.open("post", "http://localshot:8086"+ "?type=ajax",true);
xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");
xhr.setRequestHeader("Content-type", "multipart/form-data;");
// Simulated data
var fd = new FormData();
fd.append("upfile", f); //f represents a File object
fd.append("result","tskdskfjsf");
xhr.send(fd);
xhr.addEventListener('load', function(e) {
var r = e.target.response, json;
me.uploadComplete(r);
if (i == fileList.length - 1) {
$(img).remove()
}
});
The server-side code (Java) is as follows:
System.out.print(getPara("result"));
UploadFile uf = getFile("upfile", path.getAbsolutePath() + "/");
My problems are:
- I am not receiving any data in the console.
- When executing the statement
, it throws an exceptiongetFile("upfile",path.getAbsolutePath() + "/")
."java.io.IOException: Posted content type isn't multipart/form-data"
The method getFile is part of a third-party framework:
public UploadFile getFile(String parameterName, String saveDirectory) {
getFiles(saveDirectory);
return getFile(parameterName);
}
public List<UploadFile> getFiles(String saveDirectory) {
if (multipartRequest == null) {
multipartRequest = new MultipartRequest(request, saveDirectory);
request = multipartRequest;
}
return multipartRequest.getFiles();
}
Your assistance would be greatly appreciated. Thank you!