Add support for New File Version Chunked Upload
- Dominant language
- Java
- Stars
- 170
- Forks
- 189
- Avg merge
- 20h 26m
- Merged PRs (30d)
- 22
Description
### 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);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.