如果我使用正常方式上传文件,但拖放时我无法将文件传递到后端。
console.log(file);
在控制台上正确显示文件。
前端:
$('#btnSubmit').click(function (e) {
e.preventDefault();
$('#btnSubmit').html("<span class='fa fa-spinner fa-spin'></span> Creating");
$('#btnSubmit').attr('disabled',true);
var formData = new FormData(document.getElementById('creationForm'));
console.log(file);
formData.append("fileUpload", file);
$.ajax({
type: 'post',
url: '/upload/testCase',
data: formData,
enctype: 'multipart/form-data',
processData: false,
contentType: false
// success and error
}
前端
@RequestMapping(value = "/upload/testCase" , method = RequestMethod.POST)
public @ResponseBody String uploadTestCase(@RequestParam("fileUpload") MultipartFile file, ...//more stuff
The file has size 0.