Spring Multipart File with @RequestBody

不羁岁月 提交于 2019-12-05 20:01:52

I found out, that this method signature could do the job:

@ResponseBody
public Survey createSurvey(@RequestPart(required=true) SurveyPostHelper helper, @RequestPart(value="file", required = true) final MultipartFile[] images)

Important in my case was to set the MimeType in the client app. The files MimeType should be image/jpg and the SurveyPostHelpers to application/json to allow Spring to parse the json and bind it to my Object.

see an example of the client code working for me images is the list of files I want to save

var formData = new FormData();

for (var i = 0; i < images.length ; i++) {
  formData.append('images', images[i]);
}

formData.append('adData', new Blob([JSON.stringify(adData)], {
    type: "application/json"
}));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!