@RequestMapping(value = "file-upload", method = RequestMethod.POST)
@ResponseBody
public String upload(HttpServletRequest request,
@RequestParam(value = "file", required = false) MultipartFile file)
throws Exception {
byte[] bytes = file.getBytes();
String uploadDir = request.getSession().getServletContext()
.getRealPath(folder);
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
String newFileName = DateUtils.format(new Date(),
DateUtils.MILLISECOND_N);
String prefix = file.getOriginalFilename().substring(
file.getOriginalFilename().lastIndexOf("."));
FileCopyUtils.copy(bytes, new File(uploadDir + "/" + newFileName
+ prefix));
return "{'path':'" + url + "/" + newFileName + prefix + "'}";
// byte[] bytes = file.getBytes();
// String newFileName = DateUtils.format(new Date(),
// DateUtils.MILLISECOND_N);
// String prefix = file.getOriginalFilename().substring(
// file.getOriginalFilename().lastIndexOf("."));
// File dirPath = new File(folder);
// if (!dirPath.exists()) {
// dirPath.mkdirs();
// }
// FileCopyUtils
// .copy(bytes, new File(folder + "/" + newFileName + prefix));
// return "{'path':'" + url + "/" + newFileName + prefix + "'}";
}
@ResponseBody
public String upload(HttpServletRequest request,
@RequestParam(value = "file", required = false) MultipartFile file)
throws Exception {
byte[] bytes = file.getBytes();
String uploadDir = request.getSession().getServletContext()
.getRealPath(folder);
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
String newFileName = DateUtils.format(new Date(),
DateUtils.MILLISECOND_N);
String prefix = file.getOriginalFilename().substring(
file.getOriginalFilename().lastIndexOf("."));
FileCopyUtils.copy(bytes, new File(uploadDir + "/" + newFileName
+ prefix));
return "{'path':'" + url + "/" + newFileName + prefix + "'}";
// byte[] bytes = file.getBytes();
// String newFileName = DateUtils.format(new Date(),
// DateUtils.MILLISECOND_N);
// String prefix = file.getOriginalFilename().substring(
// file.getOriginalFilename().lastIndexOf("."));
// File dirPath = new File(folder);
// if (!dirPath.exists()) {
// dirPath.mkdirs();
// }
// FileCopyUtils
// .copy(bytes, new File(folder + "/" + newFileName + prefix));
// return "{'path':'" + url + "/" + newFileName + prefix + "'}";
}