if (uploadPartRequest.getMd5Digest() != null)
request.addHeader(Headers.CONTENT_MD5, uploadPartRequest.getMd5Digest());
signRequest(request, HttpMethodName.PUT, bucketName, key);
HttpRequest httpRequest = convertToHttpRequest(request, HttpMethodName.PUT);
httpRequest.addHeader(Headers.CONTENT_LENGTH, Long.toString(partSize));
InputStream inputStream = null;
if (uploadPartRequest.getInputStream() != null) {
inputStream = uploadPartRequest.getInputStream();
} else if (uploadPartRequest.getFile() != null) {
try {
inputStream = new InputSubstream(new RepeatableFileInputStream(uploadPartRequest.getFile()),
uploadPartRequest.getFileOffset(), partSize);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("The specified file doesn't exist", e);
}
} else {
throw new IllegalArgumentException("A File or InputStream must be specified when uploading part");
}
ProgressListener progressListener = uploadPartRequest.getProgressListener();
if (progressListener != null) {
inputStream = new ProgressReportingInputStream(inputStream, progressListener);
fireProgressEvent(progressListener, ProgressEvent.PART_STARTED_EVENT_CODE);
}
try {
httpRequest.setContent(inputStream);
S3MetadataResponseHandler responseHandler = new S3MetadataResponseHandler();
ObjectMetadata metadata = client.execute(httpRequest, responseHandler, errorResponseHandler);
fireProgressEvent(progressListener, ProgressEvent.PART_COMPLETED_EVENT_CODE);
UploadPartResult result = new UploadPartResult();