|
|
@@ -13,12 +13,11 @@ import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
import java.io.*; |
|
|
import java.io.*; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
@@ -71,7 +70,7 @@ public class UploadController extends BaseController { |
|
|
@PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
@PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
@ApiOperation("上传图片") |
|
|
@ApiOperation("上传图片") |
|
|
@SystemControllerLog(description = "上传图片") |
|
|
@SystemControllerLog(description = "上传图片") |
|
|
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception{ |
|
|
|
|
|
|
|
|
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq,@RequestBody Map<String,String> paramMap) throws Exception{ |
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload"); |
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload"); |
|
|
TenantEntity tenantEntity = getTenantInfo(); |
|
|
TenantEntity tenantEntity = getTenantInfo(); |
|
|
|
|
|
|
|
|
@@ -81,45 +80,34 @@ public class UploadController extends BaseController { |
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String tempFileName = UUID.randomUUID().toString(); |
|
|
|
|
|
String fileFormat = ""; |
|
|
String fileFormat = ""; |
|
|
|
|
|
|
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
if (dot >= 0) { |
|
|
if (dot >= 0) { |
|
|
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); |
|
|
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
FileOutputStream fos = null; |
|
|
|
|
|
String imgFormat = ImgUtil.getImgFormat(fileFormat); |
|
|
String imgFormat = ImgUtil.getImgFormat(fileFormat); |
|
|
if(StringUtils.isNotBlank(imgFormat)) { |
|
|
if(StringUtils.isNotBlank(imgFormat)) { |
|
|
String localImgFileName = fmUploadDir + tempFileName + "-1" + fileFormat; |
|
|
|
|
|
String localNewImgFileName = fmUploadDir + tempFileName + fileFormat; |
|
|
|
|
|
BufferedInputStream fs = null; |
|
|
|
|
|
File localFile = new File(localImgFileName); |
|
|
|
|
|
fos = new FileOutputStream(localFile); |
|
|
|
|
|
fs = (BufferedInputStream) multiReq.getInputStream(); |
|
|
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
|
|
int len = 0; |
|
|
|
|
|
while ((len = fs.read(buffer)) != -1) { |
|
|
|
|
|
fos.write(buffer, 0, len); |
|
|
|
|
|
} |
|
|
|
|
|
fos.close(); |
|
|
|
|
|
fs.close(); |
|
|
|
|
|
logger.info("local file: " + localImgFileName); |
|
|
|
|
|
File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName, imgFormat); |
|
|
|
|
|
logger.info("local new file: " + localNewImgFileName); |
|
|
|
|
|
// 删除本地缓存 |
|
|
|
|
|
localFile.delete(); |
|
|
|
|
|
ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, new FileInputStream(newFile)); |
|
|
|
|
|
// 删除本地缓存 |
|
|
|
|
|
newFile.delete(); |
|
|
|
|
|
return data; |
|
|
|
|
|
} else { |
|
|
|
|
|
ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); |
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
long maxSize = Long.parseLong(paramMap.get("size")); |
|
|
|
|
|
if(maxSize > 0 && size > maxSize*1024){ |
|
|
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_CUSTOMIZE); |
|
|
|
|
|
} |
|
|
|
|
|
int width = Integer.parseInt(paramMap.get("width")); |
|
|
|
|
|
int hight = Integer.parseInt(paramMap.get("hight")); |
|
|
|
|
|
BufferedImage bufferedImage = ImageIO.read(multiReq.getInputStream()); |
|
|
|
|
|
if(bufferedImage != null){ |
|
|
|
|
|
Integer relWidth = bufferedImage.getWidth(); |
|
|
|
|
|
Integer relHeight = bufferedImage.getHeight(); |
|
|
|
|
|
if((width > 0 && width != relWidth.intValue()) |
|
|
|
|
|
|| (hight > 0 && hight != relHeight.intValue())){ |
|
|
|
|
|
return new ResultData(ErrorCode.PICTURE_W_H_CUSTOMIZE); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); |
|
|
|
|
|
return data; |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error(e.getMessage()); |
|
|
logger.error(e.getMessage()); |
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
|