I am uploading a file using ajax to spring mvc controller using the following code
var formData = new FormData();
formData.append('file', file);
$.ajax({
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
type: 'POST',
});
I can see my data in the http post but i am getting null value in controller.
@RequestMapping(value = { "/file.htm" }, method = RequestMethod.POST)
public @ResponseBody String upload(@RequestParam(value="file",required=false) CommonsMultipartFile file
) throws IOException {
String response="";
}
I have tried with MultipartFile also. I have even tried to use MultipartHttpServletRequest and tried to obtain data from the request but cannot get it. Please let me know how to resolve it. Thanks