box / box/box-java-sdk

Add support for New File Version Chunked Upload

Abierto
#1,949 0 comentarios 0 reacciones 5 asignados Reclamado por @mwwoda Ver en GitHub
enhancement
Lenguaje dominante
Java
Estrellas
170
Forks
189
Merge medio
20 h 26 min
PR fusionados (30 d)
22

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.