I am trying to upload the file, it is working on my local system, but not working in the server.
<form class="form-group row" style="height:100px;" id="uploading" method="post" enctype="multipart/form-data">
<div class="col-md-10" align="center">
<div class="form-group row" align="center">
<label class="col-md-2 form-control-label"> File to upload:</label>
<div class="col-md-10" >
<div class="input-group">
<input type="file" class="filestyle" data-buttonName="btn-primary" name="upload" id="upload" accept="*"/>
</div>
</div>
</div>
<div class="form-group row" id="buttonzone">
<div class="col-sm-14">
<div class="input-group">
<button type="submit" class="btn btn-success" id="upload" style="margin-left: 96px;">
<i class="fa fa-cloud-upload"></i> Upload</button>
<button type="button" class="btn btn-danger" id="cancel" ><i class="fa fa-ban"></i> Cancel</button>
</div>
</div>
</div>
</div>
</form>
$("form#uploading").submit(function(){
var formData = new FormData($(this)[0]);
$.ajax({
url : '/uploadController/upload',
type: 'POST',
data: formData,
async: false,
beforeSend: beforeSendHandler,
success: function (data){
var msg=data.msg;
var obj=data.obj;
if(data.success == true){
$('#successmsg').html(msg);
$('.alert-success').show();
$('.alert-danger').hide();
setTimeout(function(){
$(".alert-success").alert('close');
}, 10000);
}else{
$('#errmsg').html(msg);
$('.alert-danger').show();
$('.alert-success').hide();
setTimeout(function(){
$(".alert-danger").alert('close');
}, 10000);
}
},
cache: false,
contentType: false,
processData: false
});
return false;
});
Java code:
@RequestMapping(value = "/uploadController/upload",headers=("content-type=multipart/*"), method = RequestMethod.POST)
public @ResponseBody StatusResponse totxnsUpload(@RequestParam("upload") MultipartFile upload, HttpServletRequest request, HttpServletResponse response) throws IOException, NoSuchFieldException, SecurityException{
logger.debug(" file upload controller");
//my logic here
}
I am getting this in browser console:
{
"timestamp":1495781126083,
"status":400,
"error":"Bad Request",
"exception":"org.springframework.web.bind.MissingServletRequestParameterException",
"message":"Required MultipartFile parameter 'upload' is not present",
"path":"/uploadController/upload"
}
But it is working on out of server, I don't what is the problem.