I have implemented a Controller to upload multiple files:
public class Image implements Serializable {
private MultipartFile file;
private Ingeger imageNumber;
...
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void handleFileUpload(@RequestBody Set<Image> images) {
...
}
I correctly checked the code using only one MultipartFile directly in the upload method using this command:
curl http://localhost:8080/upload -X POST -F 'file=@1.jpg;type=image/jpg' -H "Content-Type: multipart/form-data"
I need to extend it in three ways but don't know the correct syntax:
- POST a collection of JSON items
- Add the field "imageNumber" for each item
- Most tricky part: add a file nested to each item
I solved it using an Array instead of a Set with nested files.
Java:
cURL: