使用Dropzone.js时出错
客户端:
Dropzone.options.myDropzone = {
url: 'http://localhost:8098/uploadMultipleFiles',
paramName:"files",
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 5,
maxFilesize: 1,
method: 'post',
acceptedFiles: 'image/*',
addRemoveLinks: true,
init: function() {
dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
document.getElementById("submit-all").addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
this.on("success", function(file, responseText) {
// console.log(file);
console.log(responseText);
});
//send all the form data along with the files:
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("folderSaved", jQuery("#folderSaved").val());
});
}
}
<form action="" enctype="multipart/form-data" method="POST">
<input type="text" id ="folderSaved" name ="folderSaved" value="D:\Intellegent\AppSpringBoot\input\test1" />
<div class="dropzone" id="myDropzone"> </div>
<button type="submit" id="submit-all"> upload </button>
</form>
所有在服务器端java之后的测试:
@PostMapping("/uploadFile")
public UploadFileResponse uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("folderSaved") Path folderSaved) {
String fileName = fileStorageService.storeFile(file, folderSaved);
String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/downloadFile/")
.path(fileName)
.toUriString();
return new UploadFileResponse(fileName, fileDownloadUri,
file.getContentType(), file.getSize());
}
@PostMapping("/uploadMultipleFiles")
public List<UploadFileResponse> uploadMultipleFiles(@RequestParam("files") MultipartFile[] files, @RequestParam("folderSaved") Path folderSaved {System.out.println(files[0].getOriginalFilename());
System.out.println(folderSaved);
return Arrays.asList(files)
.stream()
.map(file -> uploadFile(file, folderSaved))
.collect(Collectors.toList());
}
当我将DropzoneJs用于UI并在服务器端的第500行出现错误
System.out.println(files[0].getOriginalFilename());
但是,当使用简单代码或邮递员测试手册(无DropzoneJs插件)时没有问题