@RequestMapping("/up") @ResponseBody public String upImg(@RequestParam("myfile") MultipartFile mfile, Long code) throws IOException { long size = mfile.getSize() / 1024; //kb if (size > 1024 || size < 10) { //判断图片大小 单位Kb return "图片尺寸不合适.范围10kb - 1024kb"; } BufferedImage image = ImageIO.read(mfile.getInputStream()); if (image == null) { //如果image=null 表示上传的不是图片格式 return "图片格式不正确."; } if (image.getHeight() != image.getWidth()) { //判断图片是否是正方形 return "非正方形图片,请上传正方形图片."; } if (image.getHeight() > 800 || image.getHeight() < 320) { //判断图片是否是在分辨率范围内,非水平分辨率,非垂直分辨率 return "是正方形图片,但是分辨率过大或过小,要求分辨率 320 至 800"; } try { BlobUpload upload = fileUploadService.uploadFile(mfile, "commodity-picture"); commodityDao.updateCommoditypicByCode(upload.getFileUrl(), Long.valueOf(code), LocalDateTime.now()); return "0"; } catch (Exception e) { e.printStackTrace(); return "图片合理,但上传异常,请联系开发"; } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。