I'm retrieving my form data and submitting it to the server using ajax. The file is not available. The other field data is available.
$('#apply-form').submit(function(e){
var formData = new FormData($(this)[0]);
$.ajax({
url: '/public/listener?CO=ATV',
type: 'POST',
dataType: 'json',
data: formData,
success: function (data) {
console.log(data);
},
cache: false,
contentType: false,
processData: false
});
return false;
});
This is how i access the request on the server side
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<Object> list = upload.parseRequest(this.request);
if(list != null){
for(Object fileItem : list){
FileItem item = (FileItem)fileItem;
if(! (item.isFormField()) )
this.item =item;
}
}
Any clue why the file is null ? Maybe i'm accessing it wrong, if so can you show me the correct way.