From 3d8ec568ecbdfab0511aff543b8b68b80c35a28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez=20Verdugo?= Date: Mon, 12 Dec 2016 10:56:54 +0100 Subject: [PATCH 1/8] Fixed bug with normal update operation (not chunked) --- .../lib/resources/files/UploadRemoteFileOperation.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 0f1b7cf7..4910eccc 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -60,8 +60,9 @@ public class UploadRemoteFileOperation extends RemoteOperation { private static final String TAG = UploadRemoteFileOperation.class.getSimpleName(); - protected static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; - protected static final String IF_MATCH_HEADER = "If-Match"; + protected static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; + protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; + protected static final String IF_MATCH_HEADER = "If-Match"; protected String mLocalPath; protected String mRemotePath; @@ -152,6 +153,10 @@ public class UploadRemoteFileOperation extends RemoteOperation { mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); } mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); + // Tell to the server what is the last modification date of the file to upload + Long timeStampLong = System.currentTimeMillis()/1000; + String timeStamp = timeStampLong.toString(); + mPutMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, timeStamp); mPutMethod.setRequestEntity(mEntity); status = client.executeMethod(mPutMethod); From 4c1f91e9ef4911fdf7205b94300ce517f56e6b4f Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 13 Dec 2016 09:01:41 +0100 Subject: [PATCH 2/8] Fix bug in chunked upload (work in progress) --- .../files/ChunkedUploadRemoteFileOperation.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index d5dd096f..4e5d2318 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -32,6 +32,7 @@ import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.util.Random; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.methods.PutMethod; import com.owncloud.android.lib.common.OwnCloudClient; @@ -49,6 +50,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation public static final long CHUNK_SIZE = 1024000; private static final String OC_CHUNKED_HEADER = "OC-Chunked"; private static final String OC_CHUNK_SIZE_HEADER = "OC-Chunk-Size"; + private static final String OC_CHUNK_X_OC_MTIME_HEADER = "X-OC-Mtime"; private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType){ @@ -99,6 +101,12 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER); mPutMethod.addRequestHeader(OC_CHUNK_SIZE_HEADER, chunkSizeStr); mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr); + + // Tell to the server what is the last modification date of the file to upload + Long timeStampLong = System.currentTimeMillis()/1000; + String timeStamp = timeStampLong.toString(); + mPutMethod.addRequestHeader(OC_CHUNK_X_OC_MTIME_HEADER, timeStamp); + ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset); mPutMethod.setRequestEntity(mEntity); if (mCancellationRequested.get()) { @@ -115,6 +123,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation status = client.executeMethod(mPutMethod); + // DELETE NEXT LINE + Header[] headers = mPutMethod.getResponseHeaders(); + if (status == 400) { InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); From 53a581868826c00b623f48158643304146c042d0 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 13 Dec 2016 10:44:38 +0100 Subject: [PATCH 3/8] Delete unnecessary line --- .../resources/files/ChunkedUploadRemoteFileOperation.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index 4e5d2318..3abd161b 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -122,10 +122,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation } status = client.executeMethod(mPutMethod); - - // DELETE NEXT LINE - Header[] headers = mPutMethod.getResponseHeaders(); - + if (status == 400) { InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); From 09612b2dd93bc6ebb4181436449f47e7d099daef Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 13 Dec 2016 10:46:33 +0100 Subject: [PATCH 4/8] Delete not needed import --- .../lib/resources/files/ChunkedUploadRemoteFileOperation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index 3abd161b..23553ef1 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -32,7 +32,6 @@ import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.util.Random; -import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.methods.PutMethod; import com.owncloud.android.lib.common.OwnCloudClient; @@ -122,7 +121,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation } status = client.executeMethod(mPutMethod); - + if (status == 400) { InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); From 0fef17a60927ab388c7e82ea4cb463b9e2ad6b37 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 13 Dec 2016 10:48:24 +0100 Subject: [PATCH 5/8] Add line breaks --- .../android/lib/resources/files/UploadRemoteFileOperation.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 4910eccc..6ff37cdd 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -153,10 +153,12 @@ public class UploadRemoteFileOperation extends RemoteOperation { mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); } mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); + // Tell to the server what is the last modification date of the file to upload Long timeStampLong = System.currentTimeMillis()/1000; String timeStamp = timeStampLong.toString(); mPutMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, timeStamp); + mPutMethod.setRequestEntity(mEntity); status = client.executeMethod(mPutMethod); From 274e0ec47b5e26ea8b7e2de5418c6a287e72650e Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 14 Dec 2016 11:40:11 +0100 Subject: [PATCH 6/8] Set modification date from the file in filesystem to the file to upload --- .../ChunkedUploadRemoteFileOperation.java | 13 +- .../files/UploadRemoteFileOperation.java | 201 +++++++++--------- 2 files changed, 105 insertions(+), 109 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index 23553ef1..c03b1e5e 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -52,14 +52,14 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation private static final String OC_CHUNK_X_OC_MTIME_HEADER = "X-OC-Mtime"; private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); - public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType){ - super(storagePath, remotePath, mimeType); + public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, String fileLastModifTimestamp){ + super(storagePath, remotePath, mimeType, fileLastModifTimestamp); } public ChunkedUploadRemoteFileOperation( - String storagePath, String remotePath, String mimeType, String requiredEtag + String storagePath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp ){ - super(storagePath, remotePath, mimeType, requiredEtag); + super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); } @Override @@ -101,10 +101,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation mPutMethod.addRequestHeader(OC_CHUNK_SIZE_HEADER, chunkSizeStr); mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr); - // Tell to the server what is the last modification date of the file to upload - Long timeStampLong = System.currentTimeMillis()/1000; - String timeStamp = timeStampLong.toString(); - mPutMethod.addRequestHeader(OC_CHUNK_X_OC_MTIME_HEADER, timeStamp); + mPutMethod.addRequestHeader(OC_CHUNK_X_OC_MTIME_HEADER, mFileLastModifTimestamp); ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset); mPutMethod.setRequestEntity(mEntity); diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 6ff37cdd..5dffe5bf 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -58,131 +58,130 @@ import com.owncloud.android.lib.common.utils.Log_OC; public class UploadRemoteFileOperation extends RemoteOperation { - private static final String TAG = UploadRemoteFileOperation.class.getSimpleName(); + private static final String TAG = UploadRemoteFileOperation.class.getSimpleName(); protected static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; protected static final String IF_MATCH_HEADER = "If-Match"; - protected String mLocalPath; - protected String mRemotePath; - protected String mMimeType; - protected PutMethod mPutMethod = null; - protected boolean mForbiddenCharsInServer = false; - protected String mRequiredEtag = null; - - protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); - protected Set mDataTransferListeners = new HashSet(); + protected String mLocalPath; + protected String mRemotePath; + protected String mMimeType; + protected String mFileLastModifTimestamp; + protected PutMethod mPutMethod = null; + protected boolean mForbiddenCharsInServer = false; + protected String mRequiredEtag = null; - protected RequestEntity mEntity = null; + protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); + protected Set mDataTransferListeners = new HashSet(); - public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType) { - mLocalPath = localPath; - mRemotePath = remotePath; - mMimeType = mimeType; - } + protected RequestEntity mEntity = null; - public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String requiredEtag) { - this(localPath, remotePath, mimeType); - mRequiredEtag = requiredEtag; - } + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String fileLastModifTimestamp) { + mLocalPath = localPath; + mRemotePath = remotePath; + mMimeType = mimeType; + mFileLastModifTimestamp = fileLastModifTimestamp; + } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - DefaultHttpMethodRetryHandler oldRetryHandler = - (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp) { + this(localPath, remotePath, mimeType, fileLastModifTimestamp); + mRequiredEtag = requiredEtag; + } - try { - // prevent that uploads are retried automatically by network library - client.getParams().setParameter( - HttpMethodParams.RETRY_HANDLER, - new DefaultHttpMethodRetryHandler(0, false) - ); + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + DefaultHttpMethodRetryHandler oldRetryHandler = + (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); - mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); + try { + // prevent that uploads are retried automatically by network library + client.getParams().setParameter( + HttpMethodParams.RETRY_HANDLER, + new DefaultHttpMethodRetryHandler(0, false) + ); - if (mCancellationRequested.get()) { - // the operation was cancelled before getting it's turn to be executed in the queue of uploads - result = new RemoteOperationResult(new OperationCancelledException()); + mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); - } else { - // perform the upload - int status = uploadFile(client); - if (mForbiddenCharsInServer){ - result = new RemoteOperationResult( - RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); - } else { - result = new RemoteOperationResult(isSuccess(status), status, - (mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); - } - } + if (mCancellationRequested.get()) { + // the operation was cancelled before getting it's turn to be executed in the queue of uploads + result = new RemoteOperationResult(new OperationCancelledException()); - } catch (Exception e) { - if (mPutMethod != null && mPutMethod.isAborted()) { - result = new RemoteOperationResult(new OperationCancelledException()); + } else { + // perform the upload + int status = uploadFile(client); + if (mForbiddenCharsInServer){ + result = new RemoteOperationResult( + RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); + } else { + result = new RemoteOperationResult(isSuccess(status), status, + (mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); + } + } - } else { - result = new RemoteOperationResult(e); - } - } finally { - // reset previous retry handler - client.getParams().setParameter( - HttpMethodParams.RETRY_HANDLER, - oldRetryHandler - ); - } - return result; - } + } catch (Exception e) { + if (mPutMethod != null && mPutMethod.isAborted()) { + result = new RemoteOperationResult(new OperationCancelledException()); - public boolean isSuccess(int status) { - return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || + } else { + result = new RemoteOperationResult(e); + } + } finally { + // reset previous retry handler + client.getParams().setParameter( + HttpMethodParams.RETRY_HANDLER, + oldRetryHandler + ); + } + return result; + } + + public boolean isSuccess(int status) { + return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT)); - } + } - protected int uploadFile(OwnCloudClient client) throws IOException { - int status = -1; - try { - File f = new File(mLocalPath); - mEntity = new FileRequestEntity(f, mMimeType); - synchronized (mDataTransferListeners) { - ((ProgressiveDataTransferer)mEntity) + protected int uploadFile(OwnCloudClient client) throws IOException { + int status = -1; + try { + File f = new File(mLocalPath); + mEntity = new FileRequestEntity(f, mMimeType); + synchronized (mDataTransferListeners) { + ((ProgressiveDataTransferer)mEntity) .addDatatransferProgressListeners(mDataTransferListeners); - } - if (mRequiredEtag != null && mRequiredEtag.length() > 0) { - mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); - } - mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); + } + if (mRequiredEtag != null && mRequiredEtag.length() > 0) { + mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); + } + mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); - // Tell to the server what is the last modification date of the file to upload - Long timeStampLong = System.currentTimeMillis()/1000; - String timeStamp = timeStampLong.toString(); - mPutMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, timeStamp); - - mPutMethod.setRequestEntity(mEntity); - status = client.executeMethod(mPutMethod); + mPutMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp); - if (status == 400) { - InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); - InputStream is = new ByteArrayInputStream( - mPutMethod.getResponseBodyAsString().getBytes()); - try { - mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); + mPutMethod.setRequestEntity(mEntity); + status = client.executeMethod(mPutMethod); - } catch (Exception e) { - mForbiddenCharsInServer = false; - Log_OC.e(TAG, "Exception reading exception from server", e); - } - } + if (status == 400) { + InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); + InputStream is = new ByteArrayInputStream( + mPutMethod.getResponseBodyAsString().getBytes()); + try { + mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); - client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); + } catch (Exception e) { + mForbiddenCharsInServer = false; + Log_OC.e(TAG, "Exception reading exception from server", e); + } + } + + client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); + + } finally { + mPutMethod.releaseConnection(); // let the connection available for other methods + } + return status; + } - } finally { - mPutMethod.releaseConnection(); // let the connection available for other methods - } - return status; - } - public Set getDataTransferListeners() { return mDataTransferListeners; } From 576231023be4859d5901b92700e192db118316ad Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 14 Dec 2016 13:39:18 +0100 Subject: [PATCH 7/8] Decrease some lines length --- .../resources/files/ChunkedUploadRemoteFileOperation.java | 6 ++++-- .../lib/resources/files/UploadRemoteFileOperation.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index c03b1e5e..3135a788 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -52,12 +52,14 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation private static final String OC_CHUNK_X_OC_MTIME_HEADER = "X-OC-Mtime"; private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); - public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, String fileLastModifTimestamp){ + public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, + String fileLastModifTimestamp){ super(storagePath, remotePath, mimeType, fileLastModifTimestamp); } public ChunkedUploadRemoteFileOperation( - String storagePath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp + String storagePath, String remotePath, String mimeType, String requiredEtag, + String fileLastModifTimestamp ){ super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); } diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 5dffe5bf..1f5ecb19 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -77,14 +77,16 @@ public class UploadRemoteFileOperation extends RemoteOperation { protected RequestEntity mEntity = null; - public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String fileLastModifTimestamp) { + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, + String fileLastModifTimestamp) { mLocalPath = localPath; mRemotePath = remotePath; mMimeType = mimeType; mFileLastModifTimestamp = fileLastModifTimestamp; } - public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp) { + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, + String requiredEtag, String fileLastModifTimestamp) { this(localPath, remotePath, mimeType, fileLastModifTimestamp); mRequiredEtag = requiredEtag; } From b9492966a53534fc78122915549d7daba4ea862b Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 15 Dec 2016 09:27:14 +0100 Subject: [PATCH 8/8] Updated test with needed params --- .../android/lib/sampleclient/MainActivity.java | 9 +++++++-- .../android/lib/test_project/TestActivity.java | 18 +++++++++++++----- .../lib/test_project/test/UploadFileTest.java | 3 +-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java index 09db872f..31cf1c79 100644 --- a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -154,10 +154,15 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, private void startUpload() { File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); - File fileToUpload = upFolder.listFiles()[0]; + File fileToUpload = upFolder.listFiles()[0]; String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String mimeType = getString(R.string.sample_file_mimetype); - UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType); + + // Get the last modification date of the file from the file system + Long timeStampLong = fileToUpload.lastModified()/1000; + String timeStamp = timeStampLong.toString(); + + UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); uploadOperation.addDatatransferProgressListener(this); uploadOperation.execute(mClient, this, mHandler); } diff --git a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java index ec4314f7..4bc107fe 100644 --- a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java +++ b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java @@ -249,10 +249,10 @@ public class TestActivity extends Activity { public RemoteOperationResult uploadFile( String storagePath, String remotePath, String mimeType ) { + return TestActivity.uploadFile(storagePath, remotePath, mimeType, mClient); } - /** Access to the library method to Upload a File * @param storagePath * @param remotePath @@ -264,14 +264,18 @@ public class TestActivity extends Activity { public static RemoteOperationResult uploadFile( String storagePath, String remotePath, String mimeType, OwnCloudClient client ) { - UploadRemoteFileOperation uploadOperation; + + String fileLastModifTimestamp = getFileLastModifTimeStamp(storagePath); + + UploadRemoteFileOperation uploadOperation; + if ((new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) { uploadOperation = new ChunkedUploadRemoteFileOperation( - storagePath, remotePath, mimeType + storagePath, remotePath, mimeType, fileLastModifTimestamp ); } else { uploadOperation = new UploadRemoteFileOperation( - storagePath, remotePath, mimeType + storagePath, remotePath, mimeType, fileLastModifTimestamp ); } @@ -381,5 +385,9 @@ public class TestActivity extends Activity { return extractedFile; } - + private static String getFileLastModifTimeStamp (String storagePath) { + File file = new File(storagePath); + Long timeStampLong = file.lastModified()/1000; + return timeStampLong.toString(); + } } diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java index 07854575..eeb6a24c 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java @@ -69,7 +69,7 @@ public class UploadFileTest extends RemoteTest { * Test Upload File without chunks */ public void testUploadFile() { - + String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH; RemoteOperationResult result = mActivity.uploadFile( mFileToUpload.getAbsolutePath(), @@ -121,5 +121,4 @@ public class UploadFileTest extends RemoteTest { } super.tearDown(); } - }