| @@ -1,6 +1,7 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.annotation.TenantIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| @@ -70,7 +71,8 @@ public class UploadController extends BaseController { | |||
| @PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||
| @ApiOperation("上传图片") | |||
| @SystemControllerLog(description = "上传图片") | |||
| public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq,@RequestParam("w") Integer width,@RequestParam("h") Integer hight,@RequestParam("size") Long maxSize) { | |||
| public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq | |||
| ,@RequestParam Map<String, String> param) { | |||
| logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload"); | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| @@ -89,15 +91,24 @@ public class UploadController extends BaseController { | |||
| try { | |||
| String imgFormat = ImgUtil.getImgFormat(fileFormat); | |||
| if(StringUtils.isNotBlank(imgFormat)) { | |||
| if(maxSize != null && size > maxSize*1024){ | |||
| long maxSize = 0l; | |||
| try { | |||
| maxSize = Long.parseLong(param.get("size")); | |||
| } catch (NumberFormatException e) {} | |||
| if(maxSize > 0l && size > maxSize*1024){ | |||
| return new ResultData(ErrorCode.PICTURE_SIZE_CUSTOMIZE); | |||
| } | |||
| BufferedImage bufferedImage = ImageIO.read(multiReq.getInputStream()); | |||
| if(bufferedImage != null){ | |||
| int width = 0;int hight = 0; | |||
| try { | |||
| width = Integer.parseInt(param.get("width")); | |||
| hight = Integer.parseInt(param.get("hight")); | |||
| } catch (NumberFormatException e) {} | |||
| Integer relWidth = bufferedImage.getWidth(); | |||
| Integer relHeight = bufferedImage.getHeight(); | |||
| if((width != null && width != relWidth.intValue()) | |||
| || (hight != null && hight != relHeight.intValue())){ | |||
| if((width > 0 && width != relWidth.intValue()) | |||
| || (hight > 0 && hight != relHeight.intValue())){ | |||
| return new ResultData(ErrorCode.PICTURE_W_H_CUSTOMIZE); | |||
| } | |||
| } | |||
| @@ -105,6 +116,9 @@ public class UploadController extends BaseController { | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } catch (NumberFormatException ne) { | |||
| logger.error(ne.getMessage()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); | |||