Need a spring rest service which needs to take input as JSON content and Multiple mutipart files.
Below is the approach I followed to handle JSON content + multiple multiparts in spring MVC controller
BackEnd Implementation :
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = {"multipart/form-data"})
public
@ResponseBody
List<String> handleFileUpload(MultipartHttpServletRequest multipartHttpServletRequest) {
InputStream jsonSteam = multipartHttpServletRequest.getFile("json").getInputStream();
InputStream fileStream1 = multipartHttpServletRequest.getFile("file1").getInputStream();
InputStream fileStream2 = multipartHttpServletRequest.getFile("file2").getInputStream();
}
Front Implementation :
Request payload :
------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="file1"; filename="deleme_bkup.sql"
Content-Type: text/x-sql
------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="file2"; filename="source.sql"
Content-Type: text/x-sql
------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="json"; filename="blob"
Content-Type: application/json
------WebKitFormBoundaryhKn3wrSAw57pRAso--
Response Headersview source
RequestHeaders :
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:5533
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryhKn3wrSAw57pRAso
Host:localhost:8080
Origin:http://localhost:8080
Pragma:no-cache