diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java index 7cce0de9f..da1bc0b7c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java @@ -35,6 +35,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.RequestEntity; @@ -53,9 +54,10 @@ * @author masensio */ -public class UploadFileRemoteOperation extends RemoteOperation { +public class UploadFileRemoteOperation extends RemoteOperation { private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; private static final String IF_MATCH_HEADER = "If-Match"; + protected static final String RESULT_ETAG_HEADER = "etag"; protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; protected static final String OC_X_OC_CTIME_HEADER = "X-OC-Ctime"; @@ -155,8 +157,8 @@ public UploadFileRemoteOperation(String localPath, } @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; DefaultHttpMethodRetryHandler oldRetryHandler = (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); @@ -175,7 +177,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (cancellationRequested.get()) { // the operation was cancelled before getting it's turn to be executed in the queue of uploads - result = new RemoteOperationResult(new OperationCancelledException()); + result = new RemoteOperationResult<>(new OperationCancelledException()); } else { // perform the upload @@ -185,12 +187,12 @@ protected RemoteOperationResult run(OwnCloudClient client) { } catch (Exception e) { if (putMethod != null && putMethod.isAborted()) { if (cancellationRequested.get() && cancellationReason != null) { - result = new RemoteOperationResult(cancellationReason); + result = new RemoteOperationResult<>(cancellationReason); } else { - result = new RemoteOperationResult(new OperationCancelledException()); + result = new RemoteOperationResult<>(new OperationCancelledException()); } } else { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); } } finally { if (disableRetries) { @@ -206,9 +208,9 @@ public boolean isSuccess(int status) { status == HttpStatus.SC_NO_CONTENT)); } - protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { + protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { int status; - RemoteOperationResult result; + RemoteOperationResult result; try { File f = new File(localPath); @@ -230,7 +232,12 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep putMethod.setRequestEntity(entity); status = client.executeMethod(putMethod); - result = new RemoteOperationResult(isSuccess(status), putMethod); + result = new RemoteOperationResult<>(isSuccess(status), putMethod); + + final Header resultEtagHeader = putMethod.getResponseHeader(RESULT_ETAG_HEADER); + if (resultEtagHeader != null) { + result.setResultData(resultEtagHeader.getValue()); + } client.exhaustResponse(putMethod.getResponseBodyAsStream());