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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| @Controller @RequestMapping(value = "/zcc") public class OssController { private static final Logger logger = Logger.getLogger(OssController.class.getName());
@RequestMapping("/upload.action") public String uploadFile() { return "/uploadFile"; }
/***/ @ResponseBody @RequestMapping("/uploadFile.action") public Object postData(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws IOException { logger.info("request" + request.getRemoteHost()); if (file.isEmpty()) { Map<String, Object> map = new HashMap<>(); map.put("msg", "上传失败"); map.put("status", "202"); map.put("list", null); return map; } logger.info("fileSize:" + file.getSize()); MyOSSUtil myOssUtil = new MyOSSUtil(); boolean isSuccess = myOssUtil.uploadFile(file); Map<String, Object> map = new HashMap<>();
if (isSuccess) { map.put("msg", "上传成功"); map.put("status", "200"); map.put("list", null); } else { map.put("msg", "上传失败"); map.put("status", "202"); map.put("list", null); } return map; }
@ResponseBody @RequestMapping("/getFileList.action") public Object getFileList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, Object> map = new HashMap<>(); map.put("msg", "查询成功"); map.put("status", "200"); map.put("list", new MyOSSUtil().getFileList()); return map; }
}
|