I checked your code with a simple Spring backend and it works fine:
@Controller public class FileController { @ResponseBody @RequestMapping(value = "/data/fileupload", method = RequestMethod.POST) public String postFile(@RequestParam(value="file", required=false) MultipartFile file, @RequestParam(value="data") Object data) throws Exception { System.out.println("data = " + data); return "OK!"; } }
I used your client side code with angular v1.1.5:
var test = { description:"Test", status: "REJECTED" }; var fd = new FormData(); fd.append('data', angular.toJson(test));
The request looks like this (copied from the network tab of the Chrome console):
Request URL:http://localhost:8080/data/fileupload Request Method:POST Status Code:200 OK Request Headers POST /data/fileupload HTTP/1.1 Host: localhost:8080 ... Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryEGiRWBFzWY6xwelb Referer: http://localhost:8080/ ... Request Payload ------WebKitFormBoundaryEGiRWBFzWY6xwelb Content-Disposition: form-data; name="data" {"description":"Test","status":"REJECTED"} ------WebKitFormBoundaryEGiRWBFzWY6xwelb--
The answer is 200 OK, and the console displays the expected: {"description":"Test","status":"REJECTED"}
source share