I am using ng-file-upload to upload files to spring rest service. Single file can be uploaded successfully, but failed when multiple files.
The code I use is below:
JavaScript:
$scope.uploadFiles = function (files) {
$scope.files = files;
if (files && files.length) {
Upload.upload({
url: 'http://localhost:8099/test/upload2',
data: {files: files}
}).then(function (response) {
$timeout(function () {
$scope.result = response.data;
});
}, function (response) {
if (response.status > 0) {
$scope.errorMsg = response.status + ': ' + response.data;
}
}, function (evt) {
$scope.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
};
Java:
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/upload2")
public void upload2(@RequestParam("files") MultipartFile[] files) throws IOException {
}
But the files array is empty, anything wrong for multiple files?
Update1:
I can see the request in network tab as below:
------WebKitFormBoundarywCLpwRaJRcmfPiBl
Content-Disposition: form-data; name="username"
qqq
------WebKitFormBoundarywCLpwRaJRcmfPiBl
Content-Disposition: form-data; name="files[0]"; filename="eagle.jpg"
Content-Type: image/jpeg
------WebKitFormBoundarywCLpwRaJRcmfPiBl
Content-Disposition: form-data; name="files[1]"; filename="eclipse.epf"
Content-Type: application/octet-stream
------WebKitFormBoundarywCLpwRaJRcmfPiBl--