上传文件通常有效,但拖放不起作用

时间:2018-03-08 11:50:43

标签: javascript java jquery spring

如果我使用正常方式上传文件,但拖放时我无法将文件传递到后端。

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.

0 个答案:

没有答案