|
@@ -1,9 +1,13 @@
|
|
|
package com.fdkankan.fyun.oss;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.aliyun.oss.HttpMethod;
|
|
|
import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.aliyun.oss.common.comm.ResponseMessage;
|
|
|
import com.aliyun.oss.model.*;
|
|
|
+import com.fdkankan.common.util.FileMd5Util;
|
|
|
import com.fdkankan.fyun.constant.FYunTypeEnum;
|
|
|
import com.fdkankan.fyun.face.AbstractFYunFileService;
|
|
|
import org.slf4j.Logger;
|
|
@@ -18,9 +22,7 @@ import org.springframework.util.StringUtils;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URL;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
@@ -81,7 +83,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
metadata.setHeader(header.getKey(), header.getValue());
|
|
|
}
|
|
|
}
|
|
|
- ossClient.putObject(bucket, remoteFilePath, file, metadata);
|
|
|
+ PutObjectResult putObjectResult = ossClient.putObject(bucket, remoteFilePath, file, metadata);
|
|
|
log.info("文件上传成功,path:{}", filePath);
|
|
|
} catch (Exception e) {
|
|
|
log.error("oss上传文件失败,filePath:"+filePath, e);
|
|
@@ -89,6 +91,35 @@ public class OssFileService extends AbstractFYunFileService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ File file = new File("D:\\Downloads\\SG-t-GjwsdgpLvDb\\wwwroot\\scene_view_data\\SG-t-GjwsdgpLvDb\\images\\pan\\high\\0.jpg");
|
|
|
+ String fileMD5 = FileMd5Util.getFileMD5(file);
|
|
|
+ System.out.println("本地文件md5:" + fileMD5);
|
|
|
+ ObjectMetadata metadata = new ObjectMetadata();
|
|
|
+ Map<String, String> tags = new HashMap<>();
|
|
|
+ tags.put("tag-a", file.getName());
|
|
|
+ metadata.setObjectTagging(tags);
|
|
|
+ OSS ossClient = new OSSClientBuilder().build("http://oss-cn-shenzhen.aliyuncs.com", "LTAI5tJwboCj3r4vUNkSmbyX", "meDy7VYAWbg8kZCKsoUZcIYQxigWOy");
|
|
|
+ PutObjectRequest request = new PutObjectRequest("4dkankan", "testdata/0.jpg", file, metadata);
|
|
|
+ request.setVersionId("123444");
|
|
|
+ PutObjectResult putObjectResult = ossClient.putObject(request);
|
|
|
+ String requestId = putObjectResult.getRequestId();
|
|
|
+ System.out.println("requestId:" + requestId);
|
|
|
+ System.out.println(System.currentTimeMillis());
|
|
|
+ boolean exist = ossClient.doesObjectExist("4dkankan", "testdata/0.jpg");
|
|
|
+ System.out.println(System.currentTimeMillis());
|
|
|
+ System.out.println("文件是否存在:" + exist);
|
|
|
+ if(!exist){
|
|
|
+ System.out.println("文件不存在");
|
|
|
+ // TODO: 2025/3/31 失败处理
|
|
|
+ }
|
|
|
+
|
|
|
+ putObjectResult.getVersionId();
|
|
|
+ System.out.println(putObjectResult.getVersionId());
|
|
|
+
|
|
|
+// System.out.println(requestId1.equals(requestId2));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String uploadFileByCommand(String bucket, String filePath, String remoteFilePath) {
|
|
|
try {
|