use of ch.cyberduck.core.box.io.swagger.client.model.UploadedPart in project cyberduck by iterate-ch.
the class BoxChunkedWriteFeature method write.
@Override
public HttpResponseOutputStream<File> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
final DelayedHttpEntityCallable<File> command = new DelayedHttpEntityCallable<File>() {
@Override
public File call(final AbstractHttpEntity entity) throws BackgroundException {
try {
final HttpRange range = HttpRange.withStatus(new TransferStatus().withLength(status.getLength()).withOffset(status.getOffset()));
final String uploadSessionId = status.getParameters().get(BoxLargeUploadService.UPLOAD_SESSION_ID);
final String overall_length = status.getParameters().get(BoxLargeUploadService.OVERALL_LENGTH);
if (log.isDebugEnabled()) {
log.debug(String.format("Send range %s for file %s", range, file));
}
final HttpPut request = new HttpPut(String.format("%s/files/upload_sessions/%s", client.getBasePath(), uploadSessionId));
// Must not overlap with the range of a part already uploaded this session.
request.addHeader(new BasicHeader(HttpHeaders.CONTENT_RANGE, String.format("bytes %d-%d/%d", range.getStart(), range.getEnd(), Long.valueOf(overall_length))));
request.addHeader(new BasicHeader("Digest", String.format("sha=%s", status.getChecksum())));
request.setEntity(entity);
final UploadedPart uploadedPart = session.getClient().execute(request, new BoxClientErrorResponseHandler<UploadedPart>() {
@Override
public UploadedPart handleEntity(final HttpEntity entity1) throws IOException {
return new JSON().getContext(null).readValue(entity1.getContent(), UploadedPart.class);
}
});
if (log.isDebugEnabled()) {
log.debug(String.format("Received response %s for upload of %s", uploadedPart, file));
}
return new File().size(status.getLength()).sha1(uploadedPart.getPart().getSha1());
} catch (HttpResponseException e) {
throw new DefaultHttpResponseExceptionMappingService().map(e);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file);
}
}
@Override
public long getContentLength() {
return -1L;
}
};
return this.write(file, status, command);
}
Aggregations