I'm trying to upload a file dynamically using AJAX and Spring MVC.
Here is what I'm doing:
Javascript function:
function initQwacCertificate(){
$('#qwac').on('change', function(){
var formData = new FormData();
var file = $('#qwac')[0].files[0];
formData.append("myFileKey", file);
$.ajax({
url : postQwac,
type : 'POST',
data : formData,
enctype : 'multipart/form-data',
contentType : false,
cache : false,
processData : false,
success : function(response) {},
});
});
};
Java controller:
@PostMapping(value = "/extractQwacCertificate", consumes = { "multipart/form-data" })
ExtractedQwacCertificate extractQwacCertificate(@RequestParam("myFileKey") MultipartFile uploadedFile) throws IOException, CertificateException {
//MyStuff
}
All that stuff return my an 400 error in my JS console that I can't understand:
Required request part 'myFileKey' is not present
But for me this 'myFileKey' is present! There is something I do in the wrong way but I don't know what! Does anyone see what's wrong ?
Thank you