Howto upload multiple files with Spring Boot and test it with cURL

后端 未结 1 1758
一整个雨季
一整个雨季 2021-01-07 13:52

I have implemented a Controller to upload multiple files:

public class Image implements Serializable {
    private MultipartFile file;
    private Ingeger im         


        
相关标签:
1条回答
  • 2021-01-07 14:06

    I solved it using an Array instead of a Set with nested files.

    Java:

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public void handleFileUpload(@RequestParam MultipartFile[] images, @RequestParam Integer[] numbers) {
       ...
    }
    

    cURL:

    curl http://localhost:8080/upload -X POST \
    -F 'files=@1.jpg;type=image/jpg' \
    -F 'numbers=1' \
    -F 'files=@2.jpg;type=image/jpg' \
    -F 'numbers=2' \
    -F 'files=@3.jpg;type=image/jpg' \
    -F 'numbers=3'
    
    0 讨论(0)
提交回复
热议问题