Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Move file after upload with chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
davigonz committed Jun 29, 2018
1 parent 2024f05 commit 7529026
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class FileUtils {
private static final String TAG = FileUtils.class.getSimpleName();

public static final String PATH_SEPARATOR = "/";
public static final String FINAl_CHUNKS_FILE = ".file";

public static String getParentPath(String remotePath) {
String parentPath = new File(remotePath).getParent();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.owncloud.android.lib.resources.files;

public class MoveRemoteChunksFileOperation extends MoveRemoteFileOperation {

/**
* Constructor.
*
* @param srcRemotePath Remote path of the file/folder to move.
* @param targetRemotePath Remove path desired for the file/folder after moving it.
* @param overwrite
*/
public MoveRemoteChunksFileOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) {
super(srcRemotePath, targetRemotePath, overwrite);
isChunkedFile = true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,6 +24,7 @@

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

import android.net.Uri;
import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;
Expand All @@ -43,10 +44,11 @@
/**
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
* in the same account.
* <p>
*
* Allows renaming the moving file/folder at the same time.
*
* @author David A. Velasco
* @author David González Verdugo
*/
public class MoveRemoteFileOperation extends RemoteOperation {

Expand All @@ -59,7 +61,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
private String mTargetRemotePath;

private boolean mOverwrite;

protected boolean isChunkedFile;

/**
* Constructor.
Expand All @@ -76,6 +78,7 @@ public MoveRemoteFileOperation(
mSrcRemotePath = srcRemotePath;
mTargetRemotePath = targetRemotePath;
mOverwrite = overwrite;
isChunkedFile = false;
}


Expand Down Expand Up @@ -106,10 +109,15 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}

/// perform remote operation
RemoteOperationResult result = null;
RemoteOperationResult result;
try {

// After finishing a chunked upload, we have to move the resulting file from uploads folder to files one,
// so this uri has to be customizable
Uri srcWebDavUri = isChunkedFile ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();

final MoveMethod move = new MoveMethod(
HttpUrl.parse( client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
HttpUrl.parse(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite);

Expand All @@ -126,7 +134,6 @@ protected RemoteOperationResult run(OwnCloudClient client) {
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
client.exhaustResponse(move.getResponseAsStream());


/// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4

Expand All @@ -151,5 +158,4 @@ protected RemoteOperationResult run(OwnCloudClient client) {
protected boolean isSuccess(int status) {
return status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT;
}

}
}

0 comments on commit 7529026

Please sign in to comment.