box / box/box-java-sdk

Add support for New File Version Chunked Upload

Đang mở
#1,949 0 bình luận 0 reaction 5 người được giao Được @mwwoda nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
Java
Star
170
Fork
189
Merge trung bình
20 giờ 26 phút
Pull request đã merge (30 ngày)
22

Mô tả

### Is your feature request related to a problem? Please describe.

Current the SDK supports uploading new file versions and chunked uploads independently

### Describe the solution you'd like

### Describe alternatives you've considered

Manually construct the the upload session. This adds roughly 40-50 lines of extra code

### Additional context

```java
public static FileFull uploadLargeFileVersion(BoxClient client, Path filePath, String fileId)
throws IOException {
long fileSize = Files.size(filePath);
String fileName = filePath.getFileName().toString();
ChunkedUploadsManager chunkedUploads = client.getChunkedUploads();
System.out.printf("Uploading %s (%,d bytes) as a new version of %s...%n", fileName, fileSize, fileId);

UploadSession session =
chunkedUploads.createFileUploadSessionForExistingFile(
fileId,
new CreateFileUploadSessionForExistingFileRequestBody.Builder(fileSize)
.fileName(fileName)
.build());
String uploadPartUrl = session.getSessionEndpoints().getUploadPart();
Hash fileHash = new Hash(HashName.SHA1);

try (InputStream stream = Files.newInputStream(filePath)) {
Iterator chunks = iterateChunks(stream, session.getPartSize(), fileSize);
PartAccumulator uploaded =
reduceIterator(
chunks,
chunkedUploads::reducer,
new PartAccumulator(-1, Collections.emptyList(), fileSize, uploadPartUrl, fileHash));

long registered =
chunkedUploads
.getFileUploadSessionPartsByUrl(session.getSessionEndpoints().getListParts())
.getTotalCount();
if (registered != session.getTotalParts()) {
throw new IllegalStateException(
String.format(
"Box registered %d of %d parts; refusing to commit.",
registered, session.getTotalParts()));
}

return chunkedUploads
.createFileUploadSessionCommitByUrl(
session.getSessionEndpoints().getCommit(),
new CreateFileUploadSessionCommitByUrlRequestBody(uploaded.getParts()),
new CreateFileUploadSessionCommitByUrlHeaders("sha=" + fileHash.digestHash("base64")))
.getEntries()
.get(0);
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.