Skip to content
Open
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
@@ -0,0 +1,12 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: MIT
*/

package com.owncloud.android.lib.resources.files

interface ChunkUploadListener {
fun isCancelled(): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ChunkedFileUploadRemoteOperation extends UploadFileRemoteOperation
private final boolean onWifiConnection;
private String uploadFolderUri;
private String destinationUri;
private ChunkUploadListener chunkUploadListener;

public ChunkedFileUploadRemoteOperation(String storagePath,
String remotePath,
Expand Down Expand Up @@ -117,6 +118,10 @@ public ChunkedFileUploadRemoteOperation(String storagePath,
this.onWifiConnection = onWifiConnection;
}

public void setChunkUploadListener(ChunkUploadListener listener) {
chunkUploadListener = listener;
}

protected static Chunk calcNextChunk(long fileSize, int chunkId, long startByte, long chunkSize) {
if (chunkId < 0 || String.valueOf(chunkId).length() > CHUNK_NAME_LENGTH) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -198,13 +203,13 @@ protected RemoteOperationResult run(OwnCloudClient client) {
// determine size of next chunk
Chunk chunk = calcNextChunk(file.length(), ++lastId, nextByte, chunkSize);

RemoteOperationResult chunkResult = uploadChunk(client, chunk);
if (!chunkResult.isSuccess()) {
return chunkResult;
if (cancellationRequested.get() || (chunkUploadListener != null && chunkUploadListener.isCancelled())) {
return new RemoteOperationResult<>(new OperationCancelledException());
}

if (cancellationRequested.get()) {
return new RemoteOperationResult(new OperationCancelledException());
final var chunkResult = uploadChunk(client, chunk);
if (!chunkResult.isSuccess()) {
return chunkResult;
}

nextByte += chunk.getLength();
Expand Down
Loading