|
@@ -0,0 +1,420 @@
|
|
|
+package com.example.fms.service;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.oss.*;
|
|
|
+import com.aliyun.oss.internal.Mimetypes;
|
|
|
+import com.aliyun.oss.model.*;
|
|
|
+import com.example.fms.common.core.base.RedisConf;
|
|
|
+import com.example.fms.common.model.dto.DownloadSysFileDTO;
|
|
|
+import com.example.fms.common.model.dto.SystemFileDTO;
|
|
|
+import com.example.fms.common.model.vo.ConfigSettingVO;
|
|
|
+import com.example.fms.common.utils.FileUtils;
|
|
|
+import com.example.fms.common.utils.JsonUtils;
|
|
|
+import com.example.fms.common.utils.RedisUtil;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.tomcat.jni.OS;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author xiexiang
|
|
|
+ * @Date 2024/3/29
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OssService {
|
|
|
+ private final FileUtils fileUtils;
|
|
|
+ private final RedisUtil redisUtil;
|
|
|
+
|
|
|
+ //创建桶
|
|
|
+ public void createBucket() throws Exception {
|
|
|
+ // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
|
|
+ String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
|
|
|
+ // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
+ String accessKeyId = "LTAI5tGyG1Q7fKprgg1nWhXj";
|
|
|
+ String accessKeySecret = "Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN";
|
|
|
+ // 填写Bucket名称。
|
|
|
+ String bucketName = "xiaoshi-pas";
|
|
|
+ // 填写资源组ID。如果不填写资源组ID,则创建的Bucket属于默认资源组。
|
|
|
+ //String rsId = "rg-aek27tc****";
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 创建CreateBucketRequest对象。
|
|
|
+ CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
|
|
|
+
|
|
|
+ // 如果创建存储空间的同时需要指定存储类型、存储空间的读写权限、数据容灾类型, 请参考如下代码。
|
|
|
+ // 此处以设置存储空间的存储类型为标准存储为例介绍。
|
|
|
+ //createBucketRequest.setStorageClass(StorageClass.Standard);
|
|
|
+ // 数据容灾类型默认为本地冗余存储,即DataRedundancyType.LRS。如果需要设置数据容灾类型为同城冗余存储,请设置为DataRedundancyType.ZRS。
|
|
|
+ //createBucketRequest.setDataRedundancyType(DataRedundancyType.ZRS);
|
|
|
+ // 设置存储空间读写权限为公共读,默认为私有。
|
|
|
+ //createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
|
|
|
+
|
|
|
+ // 在支持资源组的地域创建Bucket时,您可以为Bucket配置资源组。
|
|
|
+ //createBucketRequest.setResourceGroupId(rsId);
|
|
|
+
|
|
|
+ // 创建存储空间。
|
|
|
+ ossClient.createBucket(createBucketRequest);
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteBucket() throws Exception {
|
|
|
+ // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
|
+ String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
|
|
|
+ // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
+ String accessKeyId = "LTAI5tGyG1Q7fKprgg1nWhXj";
|
|
|
+ String accessKeySecret = "Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN";
|
|
|
+ // 填写Bucket名称。
|
|
|
+ String bucketName = "xiaoshi-pas";
|
|
|
+
|
|
|
+
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 删除存储空间。
|
|
|
+ ossClient.deleteBucket(bucketName);
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OSS下载文件
|
|
|
+ *
|
|
|
+ * @param filePath
|
|
|
+ * @param configSettingVO
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static byte[] download(String filePath, ConfigSettingVO configSettingVO) throws Exception {
|
|
|
+ String endpoint = configSettingVO.getEndPoint();
|
|
|
+ String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
+ String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
+ String bucketName = configSettingVO.getBucketName();
|
|
|
+ String objectName = filePath;
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ // 下载Object到本地文件,并保存到指定的本地路径中。如果指定的本地文件存在会覆盖,不存在则新建。
|
|
|
+ OSSObject ossObject = ossClient.getObject(new GetObjectRequest(bucketName, objectName));
|
|
|
+ //读取文件内容
|
|
|
+
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len;
|
|
|
+ while ((len = ossObject.getObjectContent().read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return outputStream.toByteArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除文件
|
|
|
+ *
|
|
|
+ * @param filePath
|
|
|
+ * @param configSettingVO
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static void delete(String filePath, ConfigSettingVO configSettingVO) throws Exception {
|
|
|
+ String endpoint = configSettingVO.getEndPoint();
|
|
|
+ String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
+ String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
+ String bucketName = configSettingVO.getBucketName();
|
|
|
+ String objectName = filePath;
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ try {
|
|
|
+ // 删除文件或目录。如果要删除目录,目录必须为空。
|
|
|
+ ossClient.deleteObject(bucketName, objectName);
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * OSS上传文件
|
|
|
+ *
|
|
|
+ * @param directory
|
|
|
+ * @param multipartFile
|
|
|
+ * @param configSettingVO
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public static SystemFileDTO upload(String directory, MultipartFile multipartFile, ConfigSettingVO configSettingVO) throws IOException {
|
|
|
+ SystemFileDTO systemFileDTO = new SystemFileDTO();
|
|
|
+ // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
|
+ String endpoint = configSettingVO.getEndPoint();
|
|
|
+ // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
+ String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
+ String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
+ // 填写Bucket名称,例如examplebucket。
|
|
|
+ String bucketName = configSettingVO.getBucketName();
|
|
|
+ // 随机生成文件名
|
|
|
+ String fileName = IdUtil.simpleUUID();
|
|
|
+ // 获取文件的后缀,不带“.”,必须是multipartFile类型
|
|
|
+ String extName = FileUtil.extName(multipartFile.getOriginalFilename());
|
|
|
+ //拼接文件完整名存入数据库表
|
|
|
+ String name = fileName + "." + extName;
|
|
|
+ // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
|
|
+ String objectName = directory + "/" + name;
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ try {
|
|
|
+ // 创建PutObjectRequest对象。
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new ByteArrayInputStream(multipartFile.getBytes()));
|
|
|
+ // 如果需要上传时设置存储类型和访问权限,请参考以下示例代码。
|
|
|
+ // ObjectMetadata metadata = new ObjectMetadata();
|
|
|
+ // metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());
|
|
|
+ // metadata.setObjectAcl(CannedAccessControlList.Private);
|
|
|
+ // putObjectRequest.setMetadata(metadata);
|
|
|
+ // 上传。
|
|
|
+ PutObjectResult result = ossClient.putObject(putObjectRequest);
|
|
|
+ systemFileDTO.setFileName(name);
|
|
|
+ systemFileDTO.setFileLength(Long.toString(multipartFile.getSize()));
|
|
|
+ systemFileDTO.setIsDelete(0);
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return systemFileDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public OSS getOssClient(ConfigSettingVO configSettingVO) {
|
|
|
+ String endpoint = configSettingVO.getEndPoint();
|
|
|
+ String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
+ String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ return ossClient;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String setUploadId(String md5, OSS ossClient, InitiateMultipartUploadRequest initiateMultipartUploadRequest) {
|
|
|
+ InitiateMultipartUploadResult upresult = ossClient.initiateMultipartUpload(initiateMultipartUploadRequest);
|
|
|
+ String uploadId = upresult.getUploadId();
|
|
|
+ redisUtil.set(md5, uploadId);
|
|
|
+ return uploadId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getUploadId(String md5) {
|
|
|
+ String uploadId = redisUtil.get(md5);
|
|
|
+ return uploadId;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void uploadChucks(File file, ConfigSettingVO configSettingVO, Integer index, String md5) throws Exception {
|
|
|
+ // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
|
+ String endpoint = configSettingVO.getEndPoint();
|
|
|
+ // 填写Bucket名称,例如examplebucket。
|
|
|
+ String bucketName = configSettingVO.getBucketName();
|
|
|
+
|
|
|
+ String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
+ String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
+
|
|
|
+ String directory = fileUtils.getDirectoryName();
|
|
|
+
|
|
|
+ String tempFileName = file.getName();
|
|
|
+ // 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。
|
|
|
+ String objectName = "zhang.XLSX";
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 创建InitiateMultipartUploadRequest对象。
|
|
|
+ InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, objectName);
|
|
|
+ //上传批次号
|
|
|
+ String uploadId = "";
|
|
|
+ if (index == 0) {
|
|
|
+ uploadId = this.setUploadId(md5, ossClient, request);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ uploadId = this.getUploadId(md5);
|
|
|
+ }
|
|
|
+ // 如果需要在初始化分片时设置请求头,请参考以下示例代码。
|
|
|
+ ObjectMetadata metadata = new ObjectMetadata();
|
|
|
+
|
|
|
+
|
|
|
+ // 根据文件自动设置ContentType。如果不设置,ContentType默认值为application/oct-srream。
|
|
|
+ if (metadata.getContentType() == null) {
|
|
|
+ metadata.setContentType(Mimetypes.getInstance().getMimetype(file, objectName));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ UploadPartRequest uploadPartRequest = new UploadPartRequest();
|
|
|
+ uploadPartRequest.setBucketName(bucketName);
|
|
|
+ uploadPartRequest.setKey(objectName);
|
|
|
+ uploadPartRequest.setUploadId(uploadId);
|
|
|
+ // 设置上传的分片流。
|
|
|
+ // 以本地文件为例说明如何创建FIleInputstream,并通过InputStream.skip()方法跳过指定数据。
|
|
|
+
|
|
|
+ InputStream instream = new FileInputStream(file);
|
|
|
+ uploadPartRequest.setInputStream(instream);
|
|
|
+ // 设置分片号。每一个上传的分片都有一个分片号,取值范围是1~10000,如果超出此范围,OSS将返回InvalidArgument错误码。
|
|
|
+ uploadPartRequest.setPartNumber(index+1);
|
|
|
+ // 每个分片不需要按顺序上传,甚至可以在不同客户端上传,OSS会按照分片号排序组成完整的文件。
|
|
|
+ UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
|
|
|
+ // 每次上传分片之后,OSS的返回结果包含PartETag。PartETag将被保存在partETags中。
|
|
|
+ // partETags是PartETag的集合。PartETag由分片的ETag和分片号组成。
|
|
|
+ List<PartETag> partETags = new ArrayList<PartETag>();
|
|
|
+ partETags.add(uploadPartResult.getPartETag());
|
|
|
+ this.addPartETags(md5,uploadPartResult.getPartETag());
|
|
|
+
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println("Caught an ClientException, which means the client encountered "
|
|
|
+ + "a serious internal problem while trying to communicate with OSS, "
|
|
|
+ + "such as not being able to access the network.");
|
|
|
+ System.out.println("Error Message:" + ce.getMessage());
|
|
|
+ } finally {
|
|
|
+// if (ossClient != null) {
|
|
|
+// ossClient.shutdown();
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPartETagRedisKey(String md5) {
|
|
|
+ String key = RedisConf.OSS_PART_TAG + RedisConf.SYMBOL_COLON + md5;
|
|
|
+ return key;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<PartETag> getPartETags(String md5) {
|
|
|
+
|
|
|
+ List<PartETag> partETags = new ArrayList<>();
|
|
|
+ String key = this.getPartETagRedisKey(md5);
|
|
|
+ String json = redisUtil.get(key);
|
|
|
+ if (json != null) {
|
|
|
+ partETags = JSONArray.parseArray(json,PartETag.class);
|
|
|
+
|
|
|
+ }
|
|
|
+ return partETags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<PartETag> addPartETags(String md5, PartETag partETag) {
|
|
|
+ List<PartETag> partETags = new ArrayList<>();
|
|
|
+ String key = this.getPartETagRedisKey(md5);
|
|
|
+ String json = redisUtil.get(key);
|
|
|
+ if (json != null) {
|
|
|
+ partETags = JsonUtils.jsonToList(json, PartETag.class);
|
|
|
+ }
|
|
|
+ partETags.add(partETag);
|
|
|
+ String jsons = JSONObject.toJSONString(partETags);
|
|
|
+ redisUtil.set(key,jsons);
|
|
|
+ return partETags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void uploadChunksMerge(ConfigSettingVO configSettingVO, String md5) throws Exception {
|
|
|
+ String directory = fileUtils.getDirectoryName();
|
|
|
+ OSS ossClient = this.getOssClient(configSettingVO);
|
|
|
+ String bucketName = configSettingVO.getBucketName();
|
|
|
+ String uploadId = redisUtil.get(md5);
|
|
|
+ String tempFileName = IdUtil.simpleUUID() + "." + "xls";
|
|
|
+ String objectName = "zhang.XLSX";
|
|
|
+ List<PartETag> partETags = this.getPartETags(md5);
|
|
|
+ // 创建CompleteMultipartUploadRequest对象。
|
|
|
+ // 在执行完成分片上传操作时,需要提供所有有效的partETags。OSS收到提交的partETags后,会逐一验证每个分片的有效性。当所有的数据分片验证通过后,OSS将把这些分片组合成一个完整的文件。
|
|
|
+ CompleteMultipartUploadRequest completeMultipartUploadRequest =
|
|
|
+ new CompleteMultipartUploadRequest(bucketName, objectName, uploadId, partETags);
|
|
|
+
|
|
|
+ // 完成分片上传。
|
|
|
+ CompleteMultipartUploadResult completeMultipartUploadResult = ossClient.completeMultipartUpload(completeMultipartUploadRequest);
|
|
|
+ System.out.println(completeMultipartUploadResult.getETag());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|