mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Chunked uploads, create chunks folder [WIP]
This commit is contained in:
parent
f218a60611
commit
2d54ece72e
@ -35,7 +35,6 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
|
||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
||||
import com.owncloud.android.lib.common.network.RedirectionPath;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
@ -58,7 +57,8 @@ import java.io.InputStream;
|
||||
public class OwnCloudClient extends HttpClient {
|
||||
|
||||
public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
|
||||
public static final String NEW_WEBDAV_PATH_4_0 = "/remote.php/dav/files/";
|
||||
public static final String NEW_WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/";
|
||||
public static final String NEW_WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/files/";
|
||||
public static final String STATUS_PATH = "/status.php";
|
||||
public static final String FILES_WEB_PATH = "/index.php/apps/files";
|
||||
|
||||
@ -284,7 +284,8 @@ public class OwnCloudClient extends HttpClient {
|
||||
int status;
|
||||
|
||||
do {
|
||||
method.setFollowRedirects(mFollowRedirects);
|
||||
//TODO Dav4Android doesn't allow follow redirections right now
|
||||
// method.setFollowRedirects(mFollowRedirects);
|
||||
status = method.execute();
|
||||
repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter);
|
||||
if (repeatWithFreshCredentials) {
|
||||
@ -293,8 +294,6 @@ public class OwnCloudClient extends HttpClient {
|
||||
} while (repeatWithFreshCredentials);
|
||||
|
||||
return status;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void checkFirstRedirection(HttpMethod method) {
|
||||
@ -422,14 +421,20 @@ public class OwnCloudClient extends HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getWebdavUri() {
|
||||
public Uri getOldFilesWebdavUri() {
|
||||
return Uri.parse(mBaseUri + WEBDAV_PATH_4_0);
|
||||
}
|
||||
|
||||
public Uri getNewWebDavUri() {
|
||||
public Uri getNewFilesWebDavUri() {
|
||||
return mCredentials instanceof OwnCloudAnonymousCredentials
|
||||
? Uri.parse(mBaseUri + NEW_WEBDAV_PATH_4_0)
|
||||
: Uri.parse(mBaseUri + NEW_WEBDAV_PATH_4_0 + mCredentials.getUsername());
|
||||
? Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0)
|
||||
: Uri.parse(mBaseUri + NEW_WEBDAV_FILES_PATH_4_0 + mCredentials.getUsername());
|
||||
}
|
||||
|
||||
public Uri getNewUploadsWebDavUri() {
|
||||
return mCredentials instanceof OwnCloudAnonymousCredentials
|
||||
? Uri.parse(mBaseUri + NEW_WEBDAV_UPLOADS_PATH_4_0)
|
||||
: Uri.parse(mBaseUri + NEW_WEBDAV_UPLOADS_PATH_4_0 + mCredentials.getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@ package com.owncloud.android.lib.common.accounts;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.httpclient.Cookie;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
@ -38,12 +37,9 @@ import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
@ -239,7 +235,7 @@ public class AccountUtils {
|
||||
// Account Manager
|
||||
AccountManager am = AccountManager.get(context.getApplicationContext());
|
||||
|
||||
Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri();
|
||||
Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getOldFilesWebdavUri();
|
||||
|
||||
String cookiesString = am.getUserData(account, Constants.KEY_COOKIES);
|
||||
if (cookiesString != null) {
|
||||
|
@ -65,19 +65,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
||||
FileChannel channel = null;
|
||||
RandomAccessFile raf = null;
|
||||
|
||||
//MKCOL
|
||||
try {
|
||||
MkColMethod mkcol = new MkColMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath))
|
||||
);
|
||||
|
||||
String a = "";
|
||||
} catch (Exception e) {
|
||||
|
||||
String b = "";
|
||||
}
|
||||
|
||||
|
||||
//TODO
|
||||
// try {
|
||||
// File file = new File(mLocalPath);
|
||||
@ -90,7 +77,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
||||
// }
|
||||
//
|
||||
// long offset = 0;
|
||||
// String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) +
|
||||
// String uriPrefix = client.getOldWebdavUri() + WebdavUtils.encodePath(mRemotePath) +
|
||||
// "-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-";
|
||||
// long totalLength = file.length();
|
||||
// long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE);
|
||||
@ -154,5 +141,4 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -104,8 +104,8 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
||||
RemoteOperationResult result = null;
|
||||
try {
|
||||
CopyMethod copyMethod = new CopyMethod(
|
||||
HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite);
|
||||
|
||||
copyMethod.setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
@ -25,6 +25,8 @@
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.webdav.MkColMethod;
|
||||
@ -53,20 +55,20 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
private static final int READ_TIMEOUT = 30000;
|
||||
private static final int CONNECTION_TIMEOUT = 5000;
|
||||
|
||||
|
||||
protected String mRemotePath;
|
||||
protected boolean mCreateFullPath;
|
||||
private String mRemotePath;
|
||||
private boolean mCreateFullPath;
|
||||
private boolean mFolderToSaveChunks;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param remotePath Full path to the new directory to create in the remote server.
|
||||
* @param createFullPath 'True' means that all the ancestor folders should be created
|
||||
* if don't exist yet.
|
||||
* @param remotePath Full path to the new directory to create in the remote server.
|
||||
* @param createFullPath 'True' means that all the ancestor folders should be created.
|
||||
* @param folderToSaveChunks 'True' means that the folder to create is to save upload chunks.
|
||||
*/
|
||||
public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
|
||||
public CreateRemoteFolderOperation(String remotePath, boolean createFullPath, boolean folderToSaveChunks) {
|
||||
mRemotePath = remotePath;
|
||||
mCreateFullPath = createFullPath;
|
||||
mFolderToSaveChunks = folderToSaveChunks;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,8 +104,8 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
private RemoteOperationResult createFolder(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
try {
|
||||
final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(client.getWebdavUri()
|
||||
+ WebdavUtils.encodePath(mRemotePath)));
|
||||
Uri webDavUri = mFolderToSaveChunks ? client.getNewUploadsWebDavUri() : client.getNewFilesWebDavUri();
|
||||
final MkColMethod mkcol = new MkColMethod(HttpUrl.parse(webDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||
mkcol.setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
mkcol.setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||
final int status = client.executeHttpMethod(mkcol);
|
||||
@ -124,7 +126,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
|
||||
private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) {
|
||||
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
|
||||
mCreateFullPath);
|
||||
mCreateFullPath, mFolderToSaveChunks);
|
||||
return operation.execute(client);
|
||||
}
|
||||
}
|
@ -37,7 +37,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -103,7 +102,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
||||
RemoteOperationResult result;
|
||||
int status;
|
||||
boolean savedFile = false;
|
||||
mGet = new GetMethod(HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)));
|
||||
mGet = new GetMethod(HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
|
||||
Iterator<OnDatatransferProgressListener> it;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
@ -88,7 +88,7 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
||||
|
||||
// client.setFollowRedirects(false);
|
||||
PropfindMethod propfindMethod = new PropfindMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mPath)),
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mPath)),
|
||||
0,
|
||||
DavUtils.getAllPropset());
|
||||
|
||||
@ -115,14 +115,14 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
||||
? new RemoteOperationResult(OK)
|
||||
: new RemoteOperationResult(propfindMethod);
|
||||
|
||||
Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() +
|
||||
Log_OC.d(TAG, "Existence check for " + client.getOldFilesWebdavUri() +
|
||||
WebdavUtils.encodePath(mPath) + " targeting for " +
|
||||
(mSuccessIfAbsent ? " absence " : " existence ") +
|
||||
"finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : ""));
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Existence check for " + client.getWebdavUri() +
|
||||
Log_OC.e(TAG, "Existence check for " + client.getOldFilesWebdavUri() +
|
||||
WebdavUtils.encodePath(mPath) + " targeting for " +
|
||||
(mSuccessIfAbsent ? " absence " : " existence ") + ": " +
|
||||
result.getLogMessage(), result.getException());
|
||||
|
@ -35,7 +35,6 @@ public class FileUtils {
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
|
||||
|
||||
public static String getParentPath(String remotePath) {
|
||||
String parentPath = new File(remotePath).getParent();
|
||||
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
|
||||
@ -82,5 +81,4 @@ public class FileUtils {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -109,8 +109,8 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
||||
RemoteOperationResult result = null;
|
||||
try {
|
||||
final MoveMethod move = new MoveMethod(
|
||||
HttpUrl.parse( client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
HttpUrl.parse( client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
mOverwrite);
|
||||
|
||||
move.setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
@ -79,7 +79,7 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
||||
try {
|
||||
// remote request
|
||||
propfind = new PropfindMethod(
|
||||
HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
HttpUrl.parse(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
DEPTH_0,
|
||||
DavUtils.getAllPropset());
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
||||
|
||||
try {
|
||||
PropfindMethod propfindMethod = new PropfindMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
DavConstants.DEPTH_1,
|
||||
DavUtils.getAllPropset());
|
||||
|
||||
|
@ -48,7 +48,7 @@ import at.bitfire.dav4android.property.owncloud.OCPrivatelink;
|
||||
import at.bitfire.dav4android.property.owncloud.OCSize;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
import static com.owncloud.android.lib.common.OwnCloudClient.NEW_WEBDAV_PATH_4_0;
|
||||
import static com.owncloud.android.lib.common.OwnCloudClient.NEW_WEBDAV_FILES_PATH_4_0;
|
||||
|
||||
/**
|
||||
* Contains the data of a Remote File from a WebDavEntry
|
||||
@ -232,7 +232,7 @@ public class RemoteFile implements Parcelable, Serializable {
|
||||
|
||||
|
||||
private static String getRemotePathFromUrl(HttpUrl url, String displayName) {
|
||||
final String pathToRemove = NEW_WEBDAV_PATH_4_0 + displayName;
|
||||
final String pathToRemove = NEW_WEBDAV_FILES_PATH_4_0 + displayName;
|
||||
return Uri.decode(url.encodedPath()).replace(pathToRemove, "");
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
|
||||
try {
|
||||
DeleteMethod deleteMethod = new DeleteMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath))
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath))
|
||||
);
|
||||
|
||||
int status = client.executeHttpMethod(deleteMethod);
|
||||
|
@ -106,9 +106,9 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||
}
|
||||
|
||||
final MoveMethod move = new MoveMethod(HttpUrl.parse(client.getWebdavUri() +
|
||||
final MoveMethod move = new MoveMethod(HttpUrl.parse(client.getNewFilesWebDavUri() +
|
||||
WebdavUtils.encodePath(mOldRemotePath)),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mNewRemotePath), false);
|
||||
|
||||
move.setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
move.setConnectionTimeout(RENAME_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
@ -89,7 +89,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
||||
|
||||
try {
|
||||
mPutMethod = new PutMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)));
|
||||
|
||||
mPutMethod.setRetryOnConnectionFailure(false);
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
||||
|
||||
try {
|
||||
PropfindMethod propfindMethod = new PropfindMethod(
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
HttpUtils.stringUrlToHttpUrl(client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mRemotePath)),
|
||||
DEPTH_0,
|
||||
DavUtils.getQuotaPropSet()
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user