From 231ad4cc890d672458b9725f1ee84da3fca92dd6 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 21:24:05 +0200 Subject: [PATCH 1/2] Use proper sizing Signed-off-by: Mario Danic --- .../ChunkedUploadRemoteFileOperation.java | 24 ++++++++++++++++++- .../files/UploadRemoteFileOperation.java | 17 ++++++++++++- 2 files changed, 39 insertions(+), 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 261f455678..fa1720533f 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -55,6 +55,7 @@ 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(); private Context mContext; + protected long mSize = 0; public ChunkedUploadRemoteFileOperation(Context context, String storagePath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp) { @@ -66,7 +67,23 @@ public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, S String requiredEtag, String fileLastModifTimestamp) { super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); } - + + public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, + String requiredEtag, String fileLastModifTimestamp, long size) { + super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); + mSize = size; + } + + public ChunkedUploadRemoteFileOperation(Context context, String storagePath, String remotePath, + String mimeType, String requiredEtag, String fileLastModifTimestamp, + long size) { + super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); + mContext = context; + mSize = size; + } + + + @Override protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { int status = -1; @@ -94,6 +111,11 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + chunkId + "-" ; long totalLength = file.length(); + + if (mSize > 0) { + totalLength = mSize; + } + long chunkCount = (long) Math.ceil((double)totalLength / CHUNK_SIZE); String chunkSizeStr = String.valueOf(CHUNK_SIZE); String totalLengthStr = String.valueOf(file.length()); diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 6b9b2ac8c8..866b9b1b37 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -66,6 +66,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { protected String mFileLastModifTimestamp; protected PutMethod mPutMethod = null; protected String mRequiredEtag = null; + protected long mSize = 0; protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); protected Set mDataTransferListeners = new HashSet(); @@ -80,6 +81,13 @@ public UploadRemoteFileOperation(String localPath, String remotePath, String mim mFileLastModifTimestamp = fileLastModifTimestamp; } + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, + String fileLastModifTimestamp, long size) { + this(localPath, remotePath, mimeType, fileLastModifTimestamp); + mSize = size; + } + + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp) { this(localPath, remotePath, mimeType, fileLastModifTimestamp); @@ -146,7 +154,14 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep if (mRequiredEtag != null && mRequiredEtag.length() > 0) { mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); } - mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); + + String lengthHeader = String.valueOf(f.length()); + + if (mSize > 0) { + lengthHeader = Long.toString(mSize); + } + + mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, lengthHeader); mPutMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp); mPutMethod.setRequestEntity(mEntity); status = client.executeMethod(mPutMethod); From 6dcd3e7eead12ce930645e578772a58b914344c8 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 31 Aug 2017 21:29:54 +0200 Subject: [PATCH 2/2] Fixes Signed-off-by: Mario Danic --- .../resources/files/ChunkedUploadRemoteFileOperation.java | 3 +-- .../lib/resources/files/UploadRemoteFileOperation.java | 7 +++++++ 2 files changed, 8 insertions(+), 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 fa1720533f..bc74226a00 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -77,8 +77,7 @@ public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, S public ChunkedUploadRemoteFileOperation(Context context, String storagePath, String remotePath, String mimeType, String requiredEtag, String fileLastModifTimestamp, long size) { - super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); - mContext = context; + this(context, storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); mSize = size; } diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 866b9b1b37..423e5161a6 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -94,6 +94,13 @@ public UploadRemoteFileOperation(String localPath, String remotePath, String mim mRequiredEtag = requiredEtag; } + public UploadRemoteFileOperation(String localPath, String remotePath, String mimeType, String requiredEtag, + String fileLastModifTimestamp, long size) { + this(localPath, remotePath, mimeType, fileLastModifTimestamp, requiredEtag); + mSize = size; + } + + @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null;