SpringMVC文件上传到服务器
@RequestMapping(path = "/pic.do")
@ResponseBody
public Map<String, Object> pic(@RequestParam("file") MultipartFile file) throws Exception {
String basepath = "http://192.168.0.1:8080/images/";
String directory = "fruit/";
String uuid_pic = UUID.randomUUID().toString().replaceAll("-", "");
String oldname = file.getOriginalFilename();
String suffix = oldname.substring(oldname.lastIndexOf("."));
String path = basepath + directory + uuid_pic + suffix;
Client client = Client.create();
WebResource webResource = client.resource(path);
Map map = new HashMap();
map.put("code", 0);
webResource.put(file.getBytes());
map.put("msg", "上传成功");
map.put("code", 100);
map.put("address", directory + uuid_pic + suffix);
return map;
}