|
@@ -6,13 +6,13 @@ import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
import com.poteviohealth.cgp.common.utils.CgpTool;
|
|
import com.poteviohealth.cgp.common.utils.CgpTool;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
|
|
@@ -38,8 +38,20 @@ public class OssUtils {
|
|
|
|
|
|
|
|
@Value("${aliyun.oss.dir}")
|
|
@Value("${aliyun.oss.dir}")
|
|
|
private String dir;
|
|
private String dir;
|
|
|
|
|
+ public VaultsResponse<String> uploadOneFile(MultipartFile dto, Long orderId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return uploadOneFile(dto,orderId,null,dto.getInputStream());
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public VaultsResponse<String> uploadOneFile(MultipartFile dto, Long orderId, InputStream inputStream) {
|
|
|
|
|
+ return uploadOneFile(dto,orderId,null,inputStream);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public VaultsResponse<String> uploadOneFile(MultipartFile dto,Long orderId) {
|
|
|
|
|
|
|
+ public VaultsResponse<String> uploadOneFile(MultipartFile dto, Long orderId,File file, InputStream inputStream) {
|
|
|
// 创建OSSClient实例。
|
|
// 创建OSSClient实例。
|
|
|
|
|
|
|
|
log.info("开始上传===");
|
|
log.info("开始上传===");
|
|
@@ -58,16 +70,13 @@ public class OssUtils {
|
|
|
String fileName = dirStr+"/S"+orderId+"N-"+ CgpTool.generateUUID() +suffix;
|
|
String fileName = dirStr+"/S"+orderId+"N-"+ CgpTool.generateUUID() +suffix;
|
|
|
// 创建PutObject请求。
|
|
// 创建PutObject请求。
|
|
|
log.info("Size=="+dto.getSize()/1024L/1024L);
|
|
log.info("Size=="+dto.getSize()/1024L/1024L);
|
|
|
- if(suffix.indexOf("mp4") != -1 && (dto.getSize() /1024L/1024L >3L)){
|
|
|
|
|
- File tempFile = File.createTempFile("temp_", ".mp4");
|
|
|
|
|
- dto.transferTo(tempFile);
|
|
|
|
|
- File outFile = this.compressVideo(tempFile);
|
|
|
|
|
- dto = new MockMultipartFile(outFile.getName(), new FileInputStream(outFile));
|
|
|
|
|
- tempFile.delete();
|
|
|
|
|
|
|
+ if(suffix.indexOf("mp4") != -1 && (dto.getSize() /1024L/1024L >3L) && file != null){
|
|
|
|
|
+ File outFile = this.compressVideo(file);
|
|
|
|
|
+ inputStream = new FileInputStream(outFile);
|
|
|
outFile.delete();
|
|
outFile.delete();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ossClient.putObject(bucketName, fileName, dto.getInputStream());
|
|
|
|
|
|
|
+ ossClient.putObject(bucketName, fileName, inputStream);
|
|
|
|
|
|
|
|
String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
|
|
String url = "https://" + bucketName + "." + endPoint + "/" + fileName;
|
|
|
// System.out.println(url);
|
|
// System.out.println(url);
|