记得上下班打卡 | git大法好,push需谨慎

Commit fca01797 authored by jiangxiulong's avatar jiangxiulong

上传数美验证图片;try优化;

parent 39a97767
......@@ -11,7 +11,6 @@ import com.aliyun.oss.model.PutObjectRequest;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.common.third.shumei.util.ShumeiUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.FilesUtils;
import com.liquidnet.commons.lang.util.IDGenerator;
......@@ -19,7 +18,6 @@ import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.dto.vo.basicServices.UploadVo;
import com.liquidnet.service.kylin.entity.PlatformOssFiles;
import com.liquidnet.service.kylin.mapper.PlatformOssFilesMapper;
import com.oracle.tools.packager.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -35,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
......@@ -99,17 +98,23 @@ public class AlOssController {
// 是否上传过 有直接返回
PlatformOssFiles ossFile = this.getOldOssFile(fileNew);
UploadVo uploadVo = new UploadVo();
try {
if (null == ossFile) {
// 上传
ossFile = this.uploadOssFile(file, pathName, buckType, resize, fileNew, isCutFrame);
}
BeanUtils.copyProperties(ossFile, uploadVo);
} finally {
// 删除临时文件 因为老文件也生成了所以也要删除
FilesUtils.deleteTempFile(fileNew);
}
if (null == ossFile) {
return ResponseDto.failure("上传失败,该文件不合规,请勿上传带有联系方式、色情、涉政、广告等敏感文件");
} else {
BeanUtils.copyProperties(ossFile, uploadVo);
return ResponseDto.success(uploadVo);
}
}
/**
* 获取老的上传文件
......@@ -142,38 +147,47 @@ public class AlOssController {
*/
private PlatformOssFiles uploadOssFile(MultipartFile file, String pathName, int buckType, int resize, File fileNew, int isCutFrame) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
String filename = "";
String contentType = "";
int size = 0;
String filename, contentType, uploadPath = "";
PlatformOssFiles ossFileVideoImg = null;
try {
if (null == file) {
filename = fileNew.getName();
Path fileNewPath = new File(fileNew.getPath()).toPath();
try {
contentType = Files.probeContentType(fileNewPath);
} catch (Exception e) {
}
size = (int) fileNew.length();
} else {
filename = file.getResource().getFilename();
contentType = file.getContentType();
size = (int) file.getSize();
}
String uploadPath = FilesUtils.getUploadPath(pathName, filename);
uploadPath = FilesUtils.getUploadPath(pathName, filename);
String bucketName = FilesUtils.getBucketName(buckType);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, uploadPath, fileNew);
ossClient.putObject(putObjectRequest);
if (1 == buckType && !shumeiUtil.checkImage(IDGenerator.nextSnowId(), imgUrl.concat(uploadPath))) {
ossClient.deleteObject(bucketName, uploadPath);
return null;
}
if (resize > 0) { // 裁切
this.ossFileResize(resize, uploadPath, bucketName, ossClient);
}
PlatformOssFiles ossFileVideoImg = null;
if (isCutFrame > 0) { // 截取帧数
ossFileVideoImg = this.ossFileCutFrame(uploadPath, pathName, buckType);
}
ossClient.shutdown();
} catch (OSSException | ClientException | IOException e) {
log.error("alOssUploadEx [e:{}]", e);
return null;
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
// 入库
PlatformOssFiles platformOssFilesDate = new PlatformOssFiles();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment