记忆力不好了,老容易忘记,笔记note一下
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public String upLoadImg(MultipartFile file, HttpServletRequest request) throws IOException {
String path = request.getSession().getServletContext().getRealPath("upload");
String fileName = file.getOriginalFilename();// 获取到上传文件的名字
// file.getSize();获取到上传文件的大小
File dir = new File(path, fileName);
if (!dir.exists()) {
dir.mkdirs();
}
// MultipartFile自带的解析方法
file.transferTo(dir);
String directory = dir.getCanonicalPath();
System.out.println("directory:" + directory);
return "/upload" + "/" + fileName;
}
网友评论