Skip to content

Commit

Permalink
Merge pull request #13336 from nextcloud/limit-max-file-upload-count
Browse files Browse the repository at this point in the history
Limit Max File Upload Count
  • Loading branch information
alperozturk96 committed Jul 30, 2024
2 parents 7f0d82f + e2caaa1 commit 37e83c3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class FileUploadHelper {
companion object {
private val TAG = FileUploadWorker::class.java.simpleName

@Suppress("MagicNumber")
const val MAX_FILE_COUNT = 500

val mBoundListeners = HashMap<String, OnDatatransferProgressListener>()

private var instance: FileUploadHelper? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ private void saveTextsFromIntent(Intent intent) {
}

private boolean somethingToUpload() {
return (mStreamsToUpload != null && mStreamsToUpload.size() > 0 && mStreamsToUpload.get(0) != null ||
return (mStreamsToUpload != null && !mStreamsToUpload.isEmpty() && mStreamsToUpload.get(0) != null ||
mUploadFromTmpFile);
}

Expand All @@ -904,6 +904,11 @@ public void uploadFiles() {
return;
}

if (mStreamsToUpload.size() > FileUploadHelper.MAX_FILE_COUNT) {
DisplayUtils.showSnackMessage(this, R.string.max_file_count_warning_message);
return;
}

UriUploader uploader = new UriUploader(
this,
mStreamsToUpload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.nextcloud.client.account.User;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.jobs.upload.FileUploadHelper;
import com.nextcloud.client.jobs.upload.FileUploadWorker;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.utils.extensions.ActivityExtensionsKt;
Expand Down Expand Up @@ -653,6 +654,11 @@ public void onClick(View v) {
@Override
public void onConfirmation(String callerTag) {
Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
if (mFileListFragment.getCheckedFilePaths().length > FileUploadHelper.MAX_FILE_COUNT) {
DisplayUtils.showSnackMessage(this, R.string.max_file_count_warning_message);
return;
}

if (QUERY_TO_MOVE_DIALOG_TAG.equals(callerTag)) {
// return the list of selected files to the caller activity (success),
// signaling that they should be moved to the ownCloud folder, instead of copied
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<string name="uploader_error_message_source_file_not_found">File selected for upload not found. Please check whether the file exists.</string>
<string name="uploader_error_message_source_file_not_copied">Could not copy file to a temporary folder. Try to resend it.</string>
<string name="uploader_upload_files_behaviour">Upload option:</string>
<string name="max_file_count_warning_message">You have reached the maximum file upload limit. Please upload fewer than 500 files at a time.</string>
<string name="uploader_upload_files_behaviour_move_to_nextcloud_folder">Move file to %1$s folder</string>
<string name="uploader_upload_files_behaviour_only_upload">Keep file in source folder</string>
<string name="uploader_upload_files_behaviour_upload_and_delete_from_source">Delete file from source folder</string>
Expand Down

0 comments on commit 37e83c3

Please sign in to comment.