【发布时间】:2016-03-30 17:12:29
【问题描述】:
在我的应用程序中,我需要上传一个文件,同时我还需要发送一个参数。 这是我的客户端代码。
$.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)
}
}
}
我的服务器端代码:
public String handleFileUpload(@RequestParam(value="file_name") MultipartFile file ,@RequestParam(value="groupName") String name){
System.out.println("file");
return "success";
}
但它说当前请求不是多部分请求。 org.springframework.web.multipart.MultipartException: 当前请求不是多部分请求
我应该如何解析文件名和其他参数?请帮忙
我的 html 表单。
<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>
【问题讨论】:
标签: java jquery html ajax spring