|
@@ -11,6 +11,7 @@ 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.model.vo.UploadChuckVO;
|
|
|
import com.example.fms.common.utils.FileUtils;
|
|
|
import com.example.fms.common.utils.JsonUtils;
|
|
|
import com.example.fms.common.utils.RedisUtil;
|
|
@@ -34,7 +35,7 @@ import java.util.List;
|
|
|
public class OssService {
|
|
|
private final FileUtils fileUtils;
|
|
|
private final RedisUtil redisUtil;
|
|
|
-
|
|
|
+ private final FileChuckService fileChuckService;
|
|
|
//创建桶
|
|
|
public void createBucket() throws Exception {
|
|
|
// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
|
@@ -292,6 +293,7 @@ public class OssService {
|
|
|
|
|
|
|
|
|
public void uploadChucks(File file, ConfigSettingVO configSettingVO, Integer index, String md5) throws Exception {
|
|
|
+ UploadChuckVO uploadChuckVO = fileChuckService.getTemFileMessage(md5);
|
|
|
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
|
String endpoint = configSettingVO.getEndPoint();
|
|
|
// 填写Bucket名称,例如examplebucket。
|
|
@@ -299,12 +301,8 @@ public class OssService {
|
|
|
|
|
|
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";
|
|
|
+ String objectName = uploadChuckVO.getFileName();
|
|
|
// 创建OSSClient实例。
|
|
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
|
|
@@ -340,14 +338,14 @@ public class OssService {
|
|
|
InputStream instream = new FileInputStream(file);
|
|
|
uploadPartRequest.setInputStream(instream);
|
|
|
// 设置分片号。每一个上传的分片都有一个分片号,取值范围是1~10000,如果超出此范围,OSS将返回InvalidArgument错误码。
|
|
|
- uploadPartRequest.setPartNumber(index+1);
|
|
|
+ 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());
|
|
|
+ this.addPartETags(md5, uploadPartResult.getPartETag());
|
|
|
|
|
|
} catch (OSSException oe) {
|
|
|
System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
@@ -379,7 +377,7 @@ public class OssService {
|
|
|
String key = this.getPartETagRedisKey(md5);
|
|
|
String json = redisUtil.get(key);
|
|
|
if (json != null) {
|
|
|
- partETags = JSONArray.parseArray(json,PartETag.class);
|
|
|
+ partETags = JSONArray.parseArray(json, PartETag.class);
|
|
|
|
|
|
}
|
|
|
return partETags;
|
|
@@ -393,18 +391,17 @@ public class OssService {
|
|
|
partETags = JsonUtils.jsonToList(json, PartETag.class);
|
|
|
}
|
|
|
partETags.add(partETag);
|
|
|
- String jsons = JSONObject.toJSONString(partETags);
|
|
|
- redisUtil.set(key,jsons);
|
|
|
- return partETags;
|
|
|
+ String jsons = JSONObject.toJSONString(partETags);
|
|
|
+ redisUtil.set(key, jsons);
|
|
|
+ return partETags;
|
|
|
}
|
|
|
|
|
|
public void uploadChunksMerge(ConfigSettingVO configSettingVO, String md5) throws Exception {
|
|
|
- String directory = fileUtils.getDirectoryName();
|
|
|
+ UploadChuckVO uploadChuckVO = fileChuckService.getTemFileMessage(md5);
|
|
|
OSS ossClient = this.getOssClient(configSettingVO);
|
|
|
String bucketName = configSettingVO.getBucketName();
|
|
|
String uploadId = redisUtil.get(md5);
|
|
|
- String tempFileName = IdUtil.simpleUUID() + "." + "xls";
|
|
|
- String objectName = "zhang.XLSX";
|
|
|
+ String objectName = uploadChuckVO.getFileName();
|
|
|
List<PartETag> partETags = this.getPartETags(md5);
|
|
|
// 创建CompleteMultipartUploadRequest对象。
|
|
|
// 在执行完成分片上传操作时,需要提供所有有效的partETags。OSS收到提交的partETags后,会逐一验证每个分片的有效性。当所有的数据分片验证通过后,OSS将把这些分片组合成一个完整的文件。
|
|
@@ -417,4 +414,15 @@ public class OssService {
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public void removeRedisKey(String md5){
|
|
|
+ String key1 =md5;
|
|
|
+ String key2 =this.getPartETagRedisKey(md5);
|
|
|
+ List<String> keys =new ArrayList<>();
|
|
|
+ keys.add(key1);
|
|
|
+ keys.add(key2);
|
|
|
+ redisUtil.delete(keys);
|
|
|
+
|
|
|
+ }
|
|
|
}
|