Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -66,7 +67,22 @@ 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) {
this(context, storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp);
mSize = size;
}



@Override
protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException {
int status = -1;
Expand Down Expand Up @@ -94,6 +110,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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
Expand All @@ -80,12 +81,26 @@ 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);
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;
Expand Down Expand Up @@ -146,7 +161,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);
Expand Down