1

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--

1 Answer 1

4

Solved by adding a parameter when posting the request: arrayKey: ''

refer to : Empty List<MultipartFile> when trying to upload many files in Spring with ng-file-upload

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.