1

It's my controller in spring boot

    @RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "multipart/form-data")
    @ResponseBody
    public ResponseEntity<?> test(
            @RequestParam("enveloppe") Enveloppe enveloppe,
            @RequestParam("files") MultipartFile[] uploadFiles) {


    }

It's my service in angularJs

var fd = new FormData();
    angular.forEach(files, function(file) {
        fd.append('files', file);
    })
    fd.append('enveloppe', enveloppe, {type :'application/xml'} );
    $http.post("/test", fd, {
        transformRequest : angular.identity,
        headers : {
            'Content-Type' : undefined
        }

My object "enveloppe" generated automatically by xsd in spring boot. my object "enveloppe" in angularjs converted by json2Xml lib to have xml. But, spring boot cant' wrapper the object enveloppe. ~

1 ) it's possible to do that ?

1

2 Answers 2

1

I found the solution with spring boot and xml for the second part with @RequestPart

My controller

@RequestMapping(value = "/test", method = RequestMethod.POST, consumes = "multipart/form-data")
    @ResponseBody
    public ResponseEntity<?> test(
            @RequestPart("enveloppe") Enveloppe enveloppe,
            @RequestPart("files") MultipartFile[] uploadFiles) {


    }

angularjs service

var fd = new FormData();
        angular.forEach(files, function(file) {
            fd.append('files', file);
        })
        fd.append('enveloppe', new Blob([enveloppe], {type: 'application/xml'}));

        $http.post("/test", fd, {
            transformRequest : angular.identity,
            headers : {
                'Content-Type' : undefined
            }
Sign up to request clarification or add additional context in comments.

Comments

0

Yes it is possible but instead appending in formData in service, i would say do it in controller

<input type="file" id="filename">

In your controller

var file=document.getElementById("filename").files[0];
var formData = new FormData();
formData.append("fileKey", file);

then send data to backend using your service.

1 Comment

I have technical constraint, I have list of file, I can to send 6 files together.

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.