@RequestPart with mixed multipart request, Spring MVC 3.2

前端 未结 5 789
长发绾君心
长发绾君心 2020-12-25 13:26

I\'m developing a RESTful service based on Spring 3.2. I\'m facing a problem with a controller handling mixed multipart HTTP request, with a Second part with XMLor JSON form

5条回答
  •  旧巷少年郎
    2020-12-25 13:52

    Not sure if you had fixed your problem, but I also had a similar problem where my JSON object was not getting picked up by my controller when mixing @RequestPart and MultipartFile together.

    The method signature for your call looks correct:

    public ResponseEntity>> createUser(
            @RequestPart("file") MultipartFile file, @RequestPart(required=false) User user) {
    
    // ... CODE ... 
    }
    

    However make sure your request looks something like this:

    POST /createUser
    Content-Type: multipart/mixed; boundary=B0EC8D07-EBF1-4EA7-966C-E492A9F2C36E
    
    --B0EC8D07-EBF1-4EA7-966C-E492A9F2C36E
    Content-Disposition: form-data; name="user";
    Content-Type: application/xml; charset=UTF-8
    
    
    --B0EC8D07-EBF1-4EA7-966C-E492A9F2C36E
    Content-Disposition: form-data; name="file"; filename="A551A700-46D4-470A-86E7-52AD2B445847.dat"
    Content-Type: application/octet-stream
    
    /// FILE DATA
    --B0EC8D07-EBF1-4EA7-966C-E492A9F2C36E--
    

提交回复
热议问题