????java:
@ResponseBody
@RequestMapping(method = RequestMethod.POST?? value = "/uploadUserPic.html")
public String saveUserPic(HttpServletRequest request??
@RequestParam(value = "userPic"?? required = true) MultipartFile file)
throws Exception {
unpackCookie(request);
String fileName = null;
String realPath = com.joytrav.Constant.FILE_REAL_PATH
+ com.joytrav.Constant.USER_UPLOAD_DIR;
if (!file.isEmpty()) {
String fileType = FileUtils.getFileType(file.getOriginalFilename());
String name = RandomUtils.getRandomFileName();
fileName = name + "." + fileType;
byte[] bytes = file.getBytes();
String newFileName = realPath + File.separator + fileName;
FileOutputStream fos = new FileOutputStream(newFileName);
fos.write(bytes); // д?????
fos.close();
File newFile = new File(newFileName);
if (newFile.isFile()) {
String url = com.joytrav.Constant.FILE_DOMAIN
+ com.joytrav.Constant.USER_UPLOAD_URL + "/"
+ fileName;
return "{'url':'" + url + "'}";
}
}
return null;
}