I am trying to upload a file and read it at the server side. But i am not able to read the file instead i am getting an exception
Required MultipartFile parameter 'file' is not present
Below is the code snippet for the same. Can you kindly tell me if i am doing something wrong here. Is there any other way to read the file sent by an ajax request at the server end.
<form id="dealform" method="post" enctype="multipart/form-data" type="file">
<input type="file" name="file" id="upload_file" style="visibility: hidden;width:0px;height:0px;"/><input id="fg-upload-button" type="submit" value="Upload" style="display:none;"/>
</form>
this.getRecord = function(params) {
var file = $('#upload_file').prop("files")[0];
$.ajax({
url : /Upload,
data : file,
type : 'POST',
dataType : 'json',
timeout : json_timeout,
error : function(){
that.notifyGetDataError('error getting:');
},
success : function(data){
that.notifyGetDataSuccess();
}
});
};
In the controller :
@RequestMapping(value = "/Upload.json", method = RequestMethod.POST)
public ModelAndView getContents(@RequestParam("file") MultipartFile file) {
}
Using the below in applicationContext.xml
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>