From e8820f2fdd04317a6c1ca5fcdb768b58dd8843a5 Mon Sep 17 00:00:00 2001 From: longshaopeng <961455570@qq.com> Date: Thu, 18 Jul 2024 12:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=85=BE=E8=AE=AF=E4=BA=91COS=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UFOPAutoConfiguration.java | 9 ++-- .../autoconfiguration/UFOPProperties.java | 6 +-- .../ufop/constant/StorageTypeEnum.java | 3 +- .../qiwenshare/ufop/factory/UFOPFactory.java | 20 ++++++- .../copy/product/TencentCOSCopier.java | 41 +++++++++++++++ .../delete/product/TencentCOSDeleter.java | 32 ++++++++++++ .../download/domain/DownloadFile.java | 2 + .../product/TencentCOSDownloader.java | 50 ++++++++++++++++++ .../operation/preview/domain/PreviewFile.java | 2 + .../preview/product/TencentCOSPreviewer.java | 45 ++++++++++++++++ .../read/product/TencentCOSReader.java | 52 +++++++++++++++++++ .../ufop/operation/upload/Uploader.java | 1 + .../upload/product/TencentCOSUploader.java | 2 +- .../write/product/TencentCOSWriter.java | 34 ++++++++++++ .../com/qiwenshare/ufop/util/UFOPUtils.java | 3 ++ 15 files changed, 291 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/qiwenshare/ufop/operation/copy/product/TencentCOSCopier.java create mode 100644 src/main/java/com/qiwenshare/ufop/operation/delete/product/TencentCOSDeleter.java create mode 100644 src/main/java/com/qiwenshare/ufop/operation/download/product/TencentCOSDownloader.java create mode 100644 src/main/java/com/qiwenshare/ufop/operation/preview/product/TencentCOSPreviewer.java create mode 100644 src/main/java/com/qiwenshare/ufop/operation/read/product/TencentCOSReader.java create mode 100644 src/main/java/com/qiwenshare/ufop/operation/write/product/TencentCOSWriter.java diff --git a/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPAutoConfiguration.java b/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPAutoConfiguration.java index 5253479..0b4a916 100644 --- a/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPAutoConfiguration.java +++ b/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPAutoConfiguration.java @@ -14,10 +14,7 @@ import com.qiwenshare.ufop.operation.delete.product.FastDFSDeleter; import com.qiwenshare.ufop.operation.download.product.FastDFSDownloader; import com.qiwenshare.ufop.operation.preview.product.FastDFSPreviewer; import com.qiwenshare.ufop.operation.read.product.FastDFSReader; -import com.qiwenshare.ufop.operation.upload.product.AliyunOSSUploader; -import com.qiwenshare.ufop.operation.upload.product.FastDFSUploader; -import com.qiwenshare.ufop.operation.upload.product.MinioUploader; -import com.qiwenshare.ufop.operation.upload.product.QiniuyunKodoUploader; +import com.qiwenshare.ufop.operation.upload.product.*; import com.qiwenshare.ufop.operation.write.product.FastDFSWriter; import com.qiwenshare.ufop.util.UFOPUtils; import lombok.extern.slf4j.Slf4j; @@ -127,4 +124,8 @@ public class UFOPAutoConfiguration { } + @Bean + public TencentCOSUploader tencentCOSUploader() { + return new TencentCOSUploader(ufopProperties.getTencent()); + } } diff --git a/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPProperties.java b/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPProperties.java index df065b1..926767d 100644 --- a/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPProperties.java +++ b/src/main/java/com/qiwenshare/ufop/autoconfiguration/UFOPProperties.java @@ -1,9 +1,6 @@ package com.qiwenshare.ufop.autoconfiguration; -import com.qiwenshare.ufop.config.AliyunConfig; -import com.qiwenshare.ufop.config.CacheConfig; -import com.qiwenshare.ufop.config.MinioConfig; -import com.qiwenshare.ufop.config.QiniuyunConfig; +import com.qiwenshare.ufop.config.*; import com.qiwenshare.ufop.domain.ThumbImage; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -20,4 +17,5 @@ public class UFOPProperties { private MinioConfig minio = new MinioConfig(); private QiniuyunConfig qiniuyun = new QiniuyunConfig(); private CacheConfig cache; + private TencentConfig tencent = new TencentConfig(); } diff --git a/src/main/java/com/qiwenshare/ufop/constant/StorageTypeEnum.java b/src/main/java/com/qiwenshare/ufop/constant/StorageTypeEnum.java index 389b258..32b61ef 100644 --- a/src/main/java/com/qiwenshare/ufop/constant/StorageTypeEnum.java +++ b/src/main/java/com/qiwenshare/ufop/constant/StorageTypeEnum.java @@ -6,7 +6,8 @@ public enum StorageTypeEnum { ALIYUN_OSS(1, "阿里云OSS对象存储"), FAST_DFS(2, "fastDFS集群存储"), MINIO(3, "minio存储"), - QINIUYUN_KODO(4, "七牛云KODO对象存储"); + QINIUYUN_KODO(4, "七牛云KODO对象存储"), + TENCENT_COS(5, "腾讯云COS对象存储"); private final int code; private final String name; diff --git a/src/main/java/com/qiwenshare/ufop/factory/UFOPFactory.java b/src/main/java/com/qiwenshare/ufop/factory/UFOPFactory.java index 4143209..8874cca 100644 --- a/src/main/java/com/qiwenshare/ufop/factory/UFOPFactory.java +++ b/src/main/java/com/qiwenshare/ufop/factory/UFOPFactory.java @@ -4,6 +4,7 @@ import com.qiwenshare.ufop.autoconfiguration.UFOPProperties; import com.qiwenshare.ufop.config.AliyunConfig; import com.qiwenshare.ufop.config.MinioConfig; import com.qiwenshare.ufop.config.QiniuyunConfig; +import com.qiwenshare.ufop.config.TencentConfig; import com.qiwenshare.ufop.constant.StorageTypeEnum; import com.qiwenshare.ufop.domain.ThumbImage; import com.qiwenshare.ufop.operation.copy.Copier; @@ -29,6 +30,7 @@ public class UFOPFactory { private ThumbImage thumbImage; private MinioConfig minioConfig; private QiniuyunConfig qiniuyunConfig; + private TencentConfig tencentConfig; @Resource private FastDFSCopier fastDFSCopier; @Resource @@ -49,7 +51,8 @@ public class UFOPFactory { private MinioUploader minioUploader; @Resource private QiniuyunKodoUploader qiniuyunKodoUploader; - + @Resource + private TencentCOSUploader tencentCOSUploader; public UFOPFactory() { } @@ -59,6 +62,7 @@ public class UFOPFactory { this.thumbImage = ufopProperties.getThumbImage(); this.minioConfig = ufopProperties.getMinio(); this.qiniuyunConfig = ufopProperties.getQiniuyun(); + this.tencentConfig = ufopProperties.getTencent(); } public Uploader getUploader() { @@ -75,6 +79,8 @@ public class UFOPFactory { uploader = minioUploader; } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == type) { uploader = qiniuyunKodoUploader; + } else if (StorageTypeEnum.TENCENT_COS.getCode() == type) { + uploader = tencentCOSUploader; } return uploader; } @@ -92,6 +98,8 @@ public class UFOPFactory { downloader = new MinioDownloader(minioConfig); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == storageType) { downloader = new QiniuyunKodoDownloader(qiniuyunConfig); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == storageType) { + downloader = new TencentCOSDownloader(tencentConfig); } return downloader; } @@ -109,6 +117,8 @@ public class UFOPFactory { deleter = new MinioDeleter(minioConfig); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == storageType) { deleter = new QiniuyunKodoDeleter(qiniuyunConfig); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == storageType) { + deleter = new TencentCOSDeleter(tencentConfig); } return deleter; } @@ -125,6 +135,8 @@ public class UFOPFactory { reader = new MinioReader(minioConfig); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == storageType) { reader = new QiniuyunKodoReader(qiniuyunConfig); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == storageType) { + reader = new TencentCOSReader(tencentConfig); } return reader; } @@ -141,6 +153,8 @@ public class UFOPFactory { writer = new MinioWriter(minioConfig); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == storageType) { writer = new QiniuyunKodoWriter(qiniuyunConfig); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == storageType) { + writer = new TencentCOSWriter(tencentConfig); } return writer; } @@ -157,6 +171,8 @@ public class UFOPFactory { previewer = new MinioPreviewer(minioConfig, thumbImage); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == storageType) { previewer = new QiniuyunKodoPreviewer(qiniuyunConfig, thumbImage); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == storageType) { + previewer = new TencentCOSPreviewer(tencentConfig, thumbImage); } return previewer; } @@ -174,6 +190,8 @@ public class UFOPFactory { copier = new MinioCopier(minioConfig); } else if (StorageTypeEnum.QINIUYUN_KODO.getCode() == type) { copier = new QiniuyunKodoCopier(qiniuyunConfig); + } else if (StorageTypeEnum.TENCENT_COS.getCode() == type) { + copier = new TencentCOSCopier(tencentConfig); } return copier; } diff --git a/src/main/java/com/qiwenshare/ufop/operation/copy/product/TencentCOSCopier.java b/src/main/java/com/qiwenshare/ufop/operation/copy/product/TencentCOSCopier.java new file mode 100644 index 0000000..792fbe9 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/copy/product/TencentCOSCopier.java @@ -0,0 +1,41 @@ +package com.qiwenshare.ufop.operation.copy.product; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.ObjectMetadata; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.operation.copy.Copier; +import com.qiwenshare.ufop.operation.copy.domain.CopyFile; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; +import org.apache.commons.io.IOUtils; + +import java.io.InputStream; +import java.util.UUID; + +public class TencentCOSCopier extends Copier { + + private TencentConfig tencentConfig; + + public TencentCOSCopier() { + + } + + public TencentCOSCopier(TencentConfig tencentConfig) { + this.tencentConfig = tencentConfig; + } + + @Override + public String copy(InputStream inputStream, CopyFile copyFile) { + String uuid = UUID.randomUUID().toString(); + String fileUrl = UFOPUtils.getUploadFileUrl(uuid, copyFile.getExtendName()); + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + try { + cosClient.putObject(tencentConfig.getCos().getBucketName(), fileUrl, inputStream, new ObjectMetadata()); + } finally { + IOUtils.closeQuietly(inputStream); + cosClient.shutdown(); + } + return fileUrl; + } + +} diff --git a/src/main/java/com/qiwenshare/ufop/operation/delete/product/TencentCOSDeleter.java b/src/main/java/com/qiwenshare/ufop/operation/delete/product/TencentCOSDeleter.java new file mode 100644 index 0000000..7e9c0b8 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/delete/product/TencentCOSDeleter.java @@ -0,0 +1,32 @@ +package com.qiwenshare.ufop.operation.delete.product; + +import com.qcloud.cos.COSClient; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.operation.delete.Deleter; +import com.qiwenshare.ufop.operation.delete.domain.DeleteFile; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; + + +public class TencentCOSDeleter extends Deleter { + private TencentConfig tencentConfig; + + public TencentCOSDeleter(){ + + } + + public TencentCOSDeleter(TencentConfig tencentConfig) { + this.tencentConfig = tencentConfig; + } + + @Override + public void delete(DeleteFile deleteFile) { + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + try { + cosClient.deleteObject(tencentConfig.getCos().getBucketName(), UFOPUtils.getTencentObjectNameByFileUrl(deleteFile.getFileUrl())); + } finally { + cosClient.shutdown(); + } + deleteCacheFile(deleteFile); + } +} diff --git a/src/main/java/com/qiwenshare/ufop/operation/download/domain/DownloadFile.java b/src/main/java/com/qiwenshare/ufop/operation/download/domain/DownloadFile.java index f589bbd..8733544 100644 --- a/src/main/java/com/qiwenshare/ufop/operation/download/domain/DownloadFile.java +++ b/src/main/java/com/qiwenshare/ufop/operation/download/domain/DownloadFile.java @@ -1,6 +1,7 @@ package com.qiwenshare.ufop.operation.download.domain; import com.aliyun.oss.OSS; +import com.qcloud.cos.COS; import lombok.Data; @Data @@ -8,4 +9,5 @@ public class DownloadFile { private String fileUrl; private OSS ossClient; private Range range; + private COS cosClient; } diff --git a/src/main/java/com/qiwenshare/ufop/operation/download/product/TencentCOSDownloader.java b/src/main/java/com/qiwenshare/ufop/operation/download/product/TencentCOSDownloader.java new file mode 100644 index 0000000..7ed3231 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/download/product/TencentCOSDownloader.java @@ -0,0 +1,50 @@ +package com.qiwenshare.ufop.operation.download.product; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.COSObject; +import com.qcloud.cos.model.GetObjectRequest; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.operation.download.Downloader; +import com.qiwenshare.ufop.operation.download.domain.DownloadFile; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; +import lombok.extern.slf4j.Slf4j; + +import java.io.InputStream; + +@Slf4j +public class TencentCOSDownloader extends Downloader { + + private TencentConfig tencentConfig; + + public TencentCOSDownloader() { + + } + + public TencentCOSDownloader(TencentConfig tencentConfig) { + this.tencentConfig = tencentConfig; + } + + @Override + public InputStream getInputStream(DownloadFile downloadFile) { + + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + + COSObject cosObject = new COSObject(); + if (downloadFile.getRange() != null) { + GetObjectRequest getObjectRequest = new GetObjectRequest(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(downloadFile.getFileUrl())); + getObjectRequest.setRange(downloadFile.getRange().getStart(), + downloadFile.getRange().getStart() + downloadFile.getRange().getLength() - 1); + cosObject = cosClient.getObject(getObjectRequest); + } else { + cosObject = cosClient.getObject(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(downloadFile.getFileUrl())); + } + + InputStream inputStream = cosObject.getObjectContent(); + + downloadFile.setCosClient(cosClient); + return inputStream; + } +} diff --git a/src/main/java/com/qiwenshare/ufop/operation/preview/domain/PreviewFile.java b/src/main/java/com/qiwenshare/ufop/operation/preview/domain/PreviewFile.java index 3e0454d..d1e1ce0 100644 --- a/src/main/java/com/qiwenshare/ufop/operation/preview/domain/PreviewFile.java +++ b/src/main/java/com/qiwenshare/ufop/operation/preview/domain/PreviewFile.java @@ -1,10 +1,12 @@ package com.qiwenshare.ufop.operation.preview.domain; import com.aliyun.oss.OSS; +import com.qcloud.cos.COS; import lombok.Data; @Data public class PreviewFile { private String fileUrl; private OSS ossClient; + private COS cosClient; } diff --git a/src/main/java/com/qiwenshare/ufop/operation/preview/product/TencentCOSPreviewer.java b/src/main/java/com/qiwenshare/ufop/operation/preview/product/TencentCOSPreviewer.java new file mode 100644 index 0000000..aa33729 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/preview/product/TencentCOSPreviewer.java @@ -0,0 +1,45 @@ +package com.qiwenshare.ufop.operation.preview.product; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.COSObject; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.domain.ThumbImage; +import com.qiwenshare.ufop.operation.preview.Previewer; +import com.qiwenshare.ufop.operation.preview.domain.PreviewFile; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.extern.slf4j.Slf4j; + +import java.io.InputStream; + +@EqualsAndHashCode(callSuper = true) +@Data +@Slf4j +public class TencentCOSPreviewer extends Previewer { + + + private TencentConfig tencentConfig; + + public TencentCOSPreviewer() { + + } + + public TencentCOSPreviewer(TencentConfig tencentConfig, ThumbImage thumbImage) { + this.tencentConfig = tencentConfig; + setThumbImage(thumbImage); + } + + + @Override + protected InputStream getInputStream(PreviewFile previewFile) { + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + COSObject cosObject = cosClient.getObject(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(previewFile.getFileUrl())); + InputStream inputStream = cosObject.getObjectContent(); + previewFile.setCosClient(cosClient); + return inputStream; + } + +} diff --git a/src/main/java/com/qiwenshare/ufop/operation/read/product/TencentCOSReader.java b/src/main/java/com/qiwenshare/ufop/operation/read/product/TencentCOSReader.java new file mode 100644 index 0000000..a311185 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/read/product/TencentCOSReader.java @@ -0,0 +1,52 @@ +package com.qiwenshare.ufop.operation.read.product; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.COSObject; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.exception.operation.ReadException; +import com.qiwenshare.ufop.operation.read.Reader; +import com.qiwenshare.ufop.operation.read.domain.ReadFile; +import com.qiwenshare.ufop.util.ReadFileUtils; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; +import org.apache.commons.io.FilenameUtils; + +import java.io.IOException; +import java.io.InputStream; + +public class TencentCOSReader extends Reader { + + private TencentConfig tencentConfig; + + public TencentCOSReader() { + + } + + public TencentCOSReader(TencentConfig tencentConfig) { + this.tencentConfig = tencentConfig; + } + + @Override + public String read(ReadFile readFile) { + String fileUrl = readFile.getFileUrl(); + String fileType = FilenameUtils.getExtension(fileUrl); + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + COSObject ossObject = cosClient.getObject(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(fileUrl)); + InputStream inputStream = ossObject.getObjectContent(); + try { + return ReadFileUtils.getContentByInputStream(fileType, inputStream); + } catch (IOException e) { + throw new ReadException("读取文件失败", e); + } finally { + cosClient.shutdown(); + } + } + + public InputStream getInputStream(String fileUrl) { + COSClient ossClient = TencentUtils.getCOSClient(tencentConfig); + COSObject cosObject = ossClient.getObject(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(fileUrl)); + return cosObject.getObjectContent(); + } +} diff --git a/src/main/java/com/qiwenshare/ufop/operation/upload/Uploader.java b/src/main/java/com/qiwenshare/ufop/operation/upload/Uploader.java index 2c786aa..8bee140 100644 --- a/src/main/java/com/qiwenshare/ufop/operation/upload/Uploader.java +++ b/src/main/java/com/qiwenshare/ufop/operation/upload/Uploader.java @@ -77,6 +77,7 @@ public abstract class Uploader { UploadFileResult uploadFileResult = doUploadFlow(qiwenMultipartFile, uploadFile); uploadFileResultList.add(uploadFileResult); } + iter.remove(); } } catch (Exception e) { throw new UploadException(e); diff --git a/src/main/java/com/qiwenshare/ufop/operation/upload/product/TencentCOSUploader.java b/src/main/java/com/qiwenshare/ufop/operation/upload/product/TencentCOSUploader.java index 3e3b471..92d2a65 100644 --- a/src/main/java/com/qiwenshare/ufop/operation/upload/product/TencentCOSUploader.java +++ b/src/main/java/com/qiwenshare/ufop/operation/upload/product/TencentCOSUploader.java @@ -106,7 +106,7 @@ public class TencentCOSUploader extends Uploader { if (uploadFile.getTotalChunks() == 1) { uploadFileResult.setFileSize(qiwenMultipartFile.getSize()); } - uploadFileResult.setStorageType(StorageTypeEnum.ALIYUN_OSS); + uploadFileResult.setStorageType(StorageTypeEnum.TENCENT_COS); uploadFileResult.setIdentifier(uploadFile.getIdentifier()); if (uploadFile.getChunkNumber() == uploadFile.getTotalChunks()) { log.info("分片上传完成"); diff --git a/src/main/java/com/qiwenshare/ufop/operation/write/product/TencentCOSWriter.java b/src/main/java/com/qiwenshare/ufop/operation/write/product/TencentCOSWriter.java new file mode 100644 index 0000000..52d5a18 --- /dev/null +++ b/src/main/java/com/qiwenshare/ufop/operation/write/product/TencentCOSWriter.java @@ -0,0 +1,34 @@ +package com.qiwenshare.ufop.operation.write.product; + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.ObjectMetadata; +import com.qiwenshare.ufop.config.TencentConfig; +import com.qiwenshare.ufop.operation.write.Writer; +import com.qiwenshare.ufop.operation.write.domain.WriteFile; +import com.qiwenshare.ufop.util.TencentUtils; +import com.qiwenshare.ufop.util.UFOPUtils; + +import java.io.InputStream; + +public class TencentCOSWriter extends Writer { + + private TencentConfig tencentConfig; + + public TencentCOSWriter() { + + } + + public TencentCOSWriter(TencentConfig tencentConfig) { + this.tencentConfig = this.tencentConfig; + } + + @Override + public void write(InputStream inputStream, WriteFile writeFile) { + COSClient cosClient = TencentUtils.getCOSClient(tencentConfig); + cosClient.putObject(tencentConfig.getCos().getBucketName(), + UFOPUtils.getTencentObjectNameByFileUrl(writeFile.getFileUrl()), inputStream, new ObjectMetadata()); + cosClient.shutdown(); + } + + +} diff --git a/src/main/java/com/qiwenshare/ufop/util/UFOPUtils.java b/src/main/java/com/qiwenshare/ufop/util/UFOPUtils.java index 8404278..b1b5400 100644 --- a/src/main/java/com/qiwenshare/ufop/util/UFOPUtils.java +++ b/src/main/java/com/qiwenshare/ufop/util/UFOPUtils.java @@ -192,4 +192,7 @@ public class UFOPUtils { return path; } + public static String getTencentObjectNameByFileUrl(String fileUrl) { + return getAliyunObjectNameByFileUrl(fileUrl); + } } -- Gitee