I am trying to upload file and other form field contents from my Angular 2 front end to Spring back end. But somehow I am not able to do it. Here is my code
You need to use @RequestPart instead of @RequestParam and set consumes attribute:
@RequestMapping(value = "/file",method = RequestMethod.POST, consumes = "multipart/form-data")
@ResponseBody
public ResponseEntity addUser(@RequestPart("uploadFile") MultipartFile file, @RequestPart("info") ExampleModel model){}
You also need to adjust your FormData object:
formData.append('uploadFile', file, file.name);
formData.append('info', new Blob([JSON.stringify(this.model)],
{
type: "application/json"
}));