Ejemplo n.º 1
0
 protected RespBody check(MultipartFile media, int type) {
   if (!ResourceType.check(type)) {
     return RespBody.fail(200);
   }
   // 文件大小小于1KB或才大于1G
   if (media.getSize() < 1 << 10 || media.getSize() > 1 << 30) {
     return RespBody.fail(201);
   }
   return RespBody.success();
 }
Ejemplo n.º 2
0
 /**
  * 文件上传
  *
  * @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);
 }
Ejemplo n.º 3
0
 /**
  * 按类型获取文件
  *
  * @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));
 }
Ejemplo n.º 4
0
 @Override
 protected RespBody check(Resource t) {
   return RespBody.success();
 }
Ejemplo n.º 5
0
 /**
  * 获取文件
  *
  * @param uid
  * @return
  */
 @RequestMapping
 @ResponseBody
 public RespBody get(@RequestParam(value = "uid", required = true) Integer uid) {
   return RespBody.success().setBody(service.get(uid));
 }