1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| @RequestMapping("upload") @ResponseBody public Map<String,Object> upload03(MultipartFile mf) throws IOException { System.out.println(mf); System.out.println(mf.getContentType()); System.out.println(mf.getName()); System.out.println(mf.getOriginalFilename()); System.out.println(mf.getSize()); System.out.println(mf.getInputStream()); String parentPath=AppFileUtils.PATH; String dirName=RandomUtils.getCurrentDateForString(); File dirFile=new File(parentPath,dirName); if(!dirFile.exists()) { dirFile.mkdirs(); } String oldName=mf.getOriginalFilename(); String newName=RandomUtils.createFileNameUseTime(oldName); File dest=new File(dirFile,newName); mf.transferTo(dest); Map<String,Object> map=new HashMap<>(); map.put("code", 0); map.put("msg", ""); Map<String,Object> data=new HashMap<>(); data.put("src", "file/downloadFile.action?path="+dirName+"/"+newName); map.put("data", data); return map; }
|