/** * 按类型获取文件 * * @param type 1:头像, 2:相册, 9:语音 * @return */ @RequestMapping(value = "/byType") @ResponseBody public RespBody getByType(@RequestParam(value = "type", required = true) Integer type) { if (type == 0) { // type = ResourceType.HEAD; throw new ServiceException(201); } return RespBody.success().setBody(service.getByType(type)); }
/** * 文件上传 * * @param type 上传类型 1:头像, 2:相册, 9:语音 * @return */ @RequestMapping(method = RequestMethod.POST) @ResponseBody public RespBody upload(@RequestParam(value = "type") int type, @RequestBody MultipartFile media) { RespBody respBody = check(media, type); if (respBody.hasError()) { return respBody; } Resource resource = null; try { resource = service.upload(media, type, getUid()); } catch (IOException e) { logger.error("上传文件错误." + e); } return respBody.setBody(resource); }
/** * 获取文件 * * @param uid * @return */ @RequestMapping @ResponseBody public RespBody get(@RequestParam(value = "uid", required = true) Integer uid) { return RespBody.success().setBody(service.get(uid)); }