|
|
@@ -80,6 +80,41 @@ public class CommonController extends AbstractApiController {
|
|
|
return R.ok(oss);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 上传OSS对象存储
|
|
|
+ */
|
|
|
+ @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
|
|
|
+ @ApiOperation("上传OSS对象存储-旋转")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "file", value = "文件", paramType = "query", dataTypeClass = File.class, required = true)
|
|
|
+ })
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping("/uploadOrient")
|
|
|
+ public R<SysOss> uploadOrient(@RequestPart("file") MultipartFile file) {
|
|
|
+ getUserId();
|
|
|
+ if (ObjectUtil.isNull(file)) {
|
|
|
+ throw new ServiceException("上传文件不能为空");
|
|
|
+ }
|
|
|
+ // 1. 将MultipartFile转为字节数组
|
|
|
+ byte[] originalBytes;
|
|
|
+ try {
|
|
|
+ originalBytes = file.getBytes();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ServiceException("上传文件不能为空");
|
|
|
+ }
|
|
|
+ // 2. 调用orientImage进行旋转处理
|
|
|
+ String mimeType = file.getContentType();
|
|
|
+ byte[] fileBytes = orientImage(originalBytes, mimeType);
|
|
|
+ // 创建临时MultipartFile
|
|
|
+ MultipartFile tempFile = new CustomMultipartFile(
|
|
|
+ fileBytes,
|
|
|
+ file.getOriginalFilename(),
|
|
|
+ mimeType
|
|
|
+ );
|
|
|
+ SysOss oss = iSysOssService.apiUpload(tempFile);
|
|
|
+ return R.ok(oss);
|
|
|
+ }
|
|
|
+
|
|
|
@FilePathSplicing(type = FilePathSplicingType.RESPONSE)
|
|
|
@ApiOperation("上传OSS对象存储")
|
|
|
@ApiImplicitParams({
|
|
|
@@ -99,6 +134,7 @@ public class CommonController extends AbstractApiController {
|
|
|
String mimeType = dataParts.length > 1 ? dataParts[0].split(":")[1].split(";")[0] : "application/octet-stream";
|
|
|
|
|
|
// 创建自定义MultipartFile
|
|
|
+ //加旋转
|
|
|
byte[] fileBytes = orientImage(Base64.getDecoder().decode(encodedData), mimeType);
|
|
|
// // 创建临时MultipartFile
|
|
|
MultipartFile file = new CustomMultipartFile(
|
|
|
@@ -112,6 +148,10 @@ public class CommonController extends AbstractApiController {
|
|
|
|
|
|
private byte[] orientImage(byte[] imageBytes, String mimeType) {
|
|
|
try {
|
|
|
+ // 1. 校验是否为图片
|
|
|
+ if (!mimeType.startsWith("image/")) {
|
|
|
+ return imageBytes;
|
|
|
+ }
|
|
|
BufferedImage original = ImageIO.read(new ByteArrayInputStream(imageBytes));
|
|
|
BufferedImage rotated = rotateImage(original, 6);
|
|
|
// 保留透明度通道(针对PNG)
|