box / box/box-java-sdk

Add support for New File Version Chunked Upload

未关闭
#1,949 0 条评论 0 个 reaction 已指派 5 人 已被 @mwwoda 认领 在 GitHub 查看
enhancement
主要语言
Java
星标
170
派生
189
平均合并
20 小时 26 分钟
30 天内合并 PR
22

描述

### 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);
}
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。