mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Move file after upload with chunks
This commit is contained in:
parent
e6bdfab11a
commit
762ae7eb62
@ -34,6 +34,7 @@ public class FileUtils {
|
|||||||
private static final String TAG = FileUtils.class.getSimpleName();
|
private static final String TAG = FileUtils.class.getSimpleName();
|
||||||
|
|
||||||
public static final String PATH_SEPARATOR = "/";
|
public static final String PATH_SEPARATOR = "/";
|
||||||
|
public static final String FINAl_CHUNKS_FILE = ".file";
|
||||||
|
|
||||||
public static String getParentPath(String remotePath) {
|
public static String getParentPath(String remotePath) {
|
||||||
String parentPath = new File(remotePath).getParent();
|
String parentPath = new File(remotePath).getParent();
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* 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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.files;
|
package com.owncloud.android.lib.resources.files;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
@ -43,10 +44,11 @@ import okhttp3.HttpUrl;
|
|||||||
/**
|
/**
|
||||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
* in the same account.
|
* in the same account.
|
||||||
* <p>
|
*
|
||||||
* Allows renaming the moving file/folder at the same time.
|
* Allows renaming the moving file/folder at the same time.
|
||||||
*
|
*
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
public class MoveRemoteFileOperation extends RemoteOperation {
|
public class MoveRemoteFileOperation extends RemoteOperation {
|
||||||
|
|
||||||
@ -59,7 +61,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
private String mTargetRemotePath;
|
private String mTargetRemotePath;
|
||||||
|
|
||||||
private boolean mOverwrite;
|
private boolean mOverwrite;
|
||||||
|
protected boolean isChunkedFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -76,6 +78,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
mSrcRemotePath = srcRemotePath;
|
mSrcRemotePath = srcRemotePath;
|
||||||
mTargetRemotePath = targetRemotePath;
|
mTargetRemotePath = targetRemotePath;
|
||||||
mOverwrite = overwrite;
|
mOverwrite = overwrite;
|
||||||
|
isChunkedFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,10 +109,15 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result;
|
||||||
try {
|
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(
|
final MoveMethod move = new MoveMethod(
|
||||||
HttpUrl.parse( client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
HttpUrl.parse(srcWebDavUri + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
mOverwrite);
|
mOverwrite);
|
||||||
|
|
||||||
@ -126,7 +134,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||||
client.exhaustResponse(move.getResponseAsStream());
|
client.exhaustResponse(move.getResponseAsStream());
|
||||||
|
|
||||||
|
|
||||||
/// for other errors that could be explicitly handled, check first:
|
/// for other errors that could be explicitly handled, check first:
|
||||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
|
|
||||||
@ -151,5 +158,4 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
protected boolean isSuccess(int status) {
|
protected boolean isSuccess(int status) {
|
||||||
return status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT;
|
return status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user