In my application I need to upload a file and along with that I need to send one more parameter. This is my code for the client side.
$.ajax({
url : "/uploadFile",
type : "POST",
data: {file_name:new FormData($("#upload-file-form")[0]),"groupName":"xxx"},
enctype : 'multipart/form-data',
// processData : false,
contentType : false,
cache : false,
success : function(data) {
if (data == "success") {
// alert ("file uploaded successfully")
$(".modal-body").html(
"<p>File uploaded Successfully</p>")
$('#myModal').modal('show');
}
if (data == "failure") {
alert("failure)
}
}
}
My code for server side :
public String handleFileUpload(@RequestParam(value="file_name") MultipartFile file ,@RequestParam(value="groupName") String name){
System.out.println("file");
return "success";
}
But it says the current request is not a MultiPart Request. org.springframework.web.multipart.MultipartException: The current request is not a multipart request
How should I parse both file name and the other parameter? please help
My html form.
<form id="upload-file-form">
<label for="upload-file-input">Upload your CSV file:</label>
<input id="upload-file-input" type="file" name="uploadfile" accept="*" class="align-right" />
<br>
<input type="submit" id ="groupUpload" value="click here to upload the file" class="btn btn-info" >
</form>