I have been trying to upload a multipart file in my Java Spring MVC Web Application using a POST REST service method. I have using the following REST service method to upload the file and this works fine when i choose the file using Postman REST service.
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload( @RequestParam("file") MultipartFile file, ModelMap model)
{
//codes
}
But when i tried to pass the multipart file as parameter to a POST REST service method in the controller. Its not working fine. So how can i pass multipart file as a queryparam to a POST REST service method.
In my controller class I have:
@RequestMapping(value = "/upload-image", method = RequestMethod.POST)
public String uploadProfileImage(@RequestParam("fileUpload") MultipartFile fileUpload, Model model, HttpServletRequest request, HttpServletResponse response)
{
// codes
}
I have the following bean in my root-context.xml file
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
Any help is appreciated.