return response;
}
// Make initial request to get the unique upload URL.
HttpResponse initialResponse = executeUploadInitiation(initiationRequestUrl);
GenericUrl uploadUrl;
try {
uploadUrl = new GenericUrl(initialResponse.getHeaders().getLocation());
} finally {
initialResponse.disconnect();
}
// Convert media content into a byte stream to upload in chunks.
contentInputStream = mediaContent.getInputStream();
if (!contentInputStream.markSupported()) {
contentInputStream = new BufferedInputStream(contentInputStream);
}
HttpResponse response;
// Upload the media content in chunks.
while (true) {
currentRequest = requestFactory.buildPutRequest(uploadUrl, null);
new MethodOverride().intercept(currentRequest); // needed for PUT
setContentAndHeadersOnCurrentRequest(bytesUploaded);
if (backOffPolicyEnabled) {
// Set MediaExponentialBackOffPolicy as the BackOffPolicy of the HTTP Request which will
// callback to this instance if there is a server error.
currentRequest.setBackOffPolicy(new MediaUploadExponentialBackOffPolicy(this));
}
currentRequest.setThrowExceptionOnExecuteError(false);
currentRequest.setRetryOnExecuteIOException(true);
response = currentRequest.execute();
boolean returningResponse = false;
try {
if (response.isSuccessStatusCode()) {
bytesUploaded = mediaContentLength;
contentInputStream.close();
updateStateAndNotifyListener(UploadState.MEDIA_COMPLETE);
returningResponse = true;
return response;
}
if (response.getStatusCode() != 308) {
returningResponse = true;
return response;
}
// Check to see if the upload URL has changed on the server.
String updatedUploadUrl = response.getHeaders().getLocation();
if (updatedUploadUrl != null) {
uploadUrl = new GenericUrl(updatedUploadUrl);
}
bytesUploaded = getNextByteIndex(response.getHeaders().getRange());
updateStateAndNotifyListener(UploadState.MEDIA_IN_PROGRESS);
} finally {
if (!returningResponse) {