Parcourir la source

oss-store 大文件分片上传接口实现中

reghao il y a 1 an
Parent
commit
0133e07058

+ 7 - 1
oss-api/src/main/java/cn/reghao/oss/api/rest/UploadedPart.java

@@ -4,6 +4,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -27,7 +28,12 @@ public class UploadedPart implements Serializable {
         this.skipUpload = true;
     }
 
-    public UploadedPart(List<Integer> uploaded) {
+    public UploadedPart() {
+        this.skipUpload = false;
+        this.uploaded = Collections.emptyList();
+    }
+
+    public void setUploaded(List<Integer> uploaded) {
         this.uploaded = uploaded;
     }
 }

+ 4 - 4
oss-store/src/main/java/cn/reghao/oss/store/service/ObjectMultipartUploadService.java

@@ -27,8 +27,6 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class ObjectMultipartUploadService {
-    // 20MB
-    private final static long PART_SIZE = 1024*1024*20;
     private final ObjectRepository objectRepository;
     private final FileStoreService fileStoreService;
     private final ObjectNameService objectNameService;
@@ -63,16 +61,18 @@ public class ObjectMultipartUploadService {
             return new UploadedPart(objectId, url);
         }
 
+        UploadedPart uploadedPart = new UploadedPart();
         FileMultipart fileMultipart = filePartRepository.getFileMultipart(sha256sum);
         if (fileMultipart == null) {
-            return null;
+            return uploadedPart;
         }
 
         String contentId = fileMultipart.getContentId();
         List<Integer> list = filePartRepository.getFileParts(contentId).stream()
                 .map(FilePart::getChunkNumber)
                 .collect(Collectors.toList());
-        return new UploadedPart(list);
+        uploadedPart.setUploaded(list);
+        return uploadedPart;
     }
 
     /**