我想用RestTemplate客户端上传图片,并使用Spring基础REST服务器获取POST请求并保存在服务器上。任何人都可以帮助我如何用我的Spring基本客户端和服务器来做到这一点。由于使用Spring REST上传图片
我的一些春天的REST API基础服务器方法如下,
@RequestMapping(value="user/upload/{imageFile}", method=RequestMethod.POST)
public @ResponseBody User upload(@RequestBody User user, @PathVariable File imageFile, HttpServletResponse response) {
// TODO - How I get this image and file and save, whether I can POST this image file with User object
}
我的一些远程客户端的春天RestTemplate基础代码如下,
User newUser = new User();
Map<String, String> vars = new HashMap<String, String>();
vars.put("imageFile", imageFile);
ResponseEntity<User> REcreateUser = restTemplate.postForEntity(IMC_LAB_SKELETON_URL + "/user/upload/{imageFile}", newUser, User.class, vars);
User createUser = REcreateUser.getBody();
// TODO - How I can POST this image file as a parameter or content of the User object