|
@@ -12,6 +12,7 @@ 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.ExcuteConfigUtils;
|
|
|
import com.example.fms.common.utils.FileUtils;
|
|
|
import com.example.fms.common.utils.JsonUtils;
|
|
|
import com.example.fms.common.utils.RedisUtil;
|
|
@@ -36,6 +37,7 @@ 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,8 +294,11 @@ public class OssService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void uploadChucks(File file, ConfigSettingVO configSettingVO, Integer index, String md5) throws Exception {
|
|
|
+ public void uploadChucks(File file, Integer index, String md5) throws Exception {
|
|
|
UploadChuckVO uploadChuckVO = fileChuckService.getTemFileMessage(md5);
|
|
|
+ List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
+ //2.根据传入id,获得配置类,根据配置类中的id去匹配sourceId来选择使用的上传方法
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(uploadChuckVO.getSourceId())).findFirst().orElse(null);
|
|
|
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
|
String endpoint = configSettingVO.getEndPoint();
|
|
|
// 填写Bucket名称,例如examplebucket。
|
|
@@ -302,7 +307,7 @@ public class OssService {
|
|
|
String accessKeyId = configSettingVO.getAccessKeyId();
|
|
|
String accessKeySecret = configSettingVO.getAccessKeySecret();
|
|
|
// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。
|
|
|
- String objectName = uploadChuckVO.getFileName();
|
|
|
+ String objectName = uploadChuckVO.getFilePath() + uploadChuckVO.getFileName();
|
|
|
// 创建OSSClient实例。
|
|
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
|
|
@@ -367,6 +372,7 @@ public class OssService {
|
|
|
}
|
|
|
|
|
|
public String getPartETagRedisKey(String md5) {
|
|
|
+
|
|
|
String key = RedisConf.OSS_PART_TAG + RedisConf.SYMBOL_COLON + md5;
|
|
|
return key;
|
|
|
}
|
|
@@ -388,7 +394,7 @@ public class OssService {
|
|
|
String key = this.getPartETagRedisKey(md5);
|
|
|
String json = redisUtil.get(key);
|
|
|
if (json != null) {
|
|
|
- partETags = JsonUtils.jsonToList(json, PartETag.class);
|
|
|
+ partETags = JSONArray.parseArray(json, PartETag.class);
|
|
|
}
|
|
|
partETags.add(partETag);
|
|
|
String jsons = JSONObject.toJSONString(partETags);
|
|
@@ -396,12 +402,15 @@ public class OssService {
|
|
|
return partETags;
|
|
|
}
|
|
|
|
|
|
- public void uploadChunksMerge(ConfigSettingVO configSettingVO, String md5) throws Exception {
|
|
|
+ public void uploadChunksMerge(String md5) throws Exception {
|
|
|
UploadChuckVO uploadChuckVO = fileChuckService.getTemFileMessage(md5);
|
|
|
+ List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
+ //2.根据传入id,获得配置类,根据配置类中的id去匹配sourceId来选择使用的上传方法
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(uploadChuckVO.getSourceId())).findFirst().orElse(null);
|
|
|
OSS ossClient = this.getOssClient(configSettingVO);
|
|
|
String bucketName = configSettingVO.getBucketName();
|
|
|
String uploadId = redisUtil.get(md5);
|
|
|
- String objectName = uploadChuckVO.getFileName();
|
|
|
+ String objectName = uploadChuckVO.getFilePath() + uploadChuckVO.getFileName();
|
|
|
List<PartETag> partETags = this.getPartETags(md5);
|
|
|
// 创建CompleteMultipartUploadRequest对象。
|
|
|
// 在执行完成分片上传操作时,需要提供所有有效的partETags。OSS收到提交的partETags后,会逐一验证每个分片的有效性。当所有的数据分片验证通过后,OSS将把这些分片组合成一个完整的文件。
|
|
@@ -411,15 +420,15 @@ public class OssService {
|
|
|
// 完成分片上传。
|
|
|
CompleteMultipartUploadResult completeMultipartUploadResult = ossClient.completeMultipartUpload(completeMultipartUploadRequest);
|
|
|
System.out.println(completeMultipartUploadResult.getETag());
|
|
|
-
|
|
|
+ this.removeRedisKey(md5);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void removeRedisKey(String md5){
|
|
|
- String key1 =md5;
|
|
|
- String key2 =this.getPartETagRedisKey(md5);
|
|
|
- List<String> keys =new ArrayList<>();
|
|
|
+ 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);
|