mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Use remoteId of the just copied file
This commit is contained in:
parent
07cdef9afa
commit
90cef9fcf6
@ -50,6 +50,7 @@ public class HttpConstants {
|
|||||||
public static final String CONTENT_TYPE_URLENCODED_UTF8 = "application/x-www-form-urlencoded; charset=utf-8";
|
public static final String CONTENT_TYPE_URLENCODED_UTF8 = "application/x-www-form-urlencoded; charset=utf-8";
|
||||||
public static final String ACCEPT_ENCODING_HEADER = "Accept-Encoding";
|
public static final String ACCEPT_ENCODING_HEADER = "Accept-Encoding";
|
||||||
public static final String ACCEPT_ENCODING_IDENTITY = "identity";
|
public static final String ACCEPT_ENCODING_IDENTITY = "identity";
|
||||||
|
public static final String OC_FILE_REMOTE_ID = "OC-FileId";
|
||||||
|
|
||||||
/***********************************************************************************************************
|
/***********************************************************************************************************
|
||||||
************************************************ STATUS CODES *********************************************
|
************************************************ STATUS CODES *********************************************
|
||||||
|
@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
*/
|
*/
|
||||||
public class CopyRemoteFileOperation extends RemoteOperation {
|
public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
||||||
|
|
||||||
private static final String TAG = CopyRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = CopyRemoteFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -80,8 +80,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
* @param client Client object to communicate with the remote ownCloud server.
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<String> run(OwnCloudClient client) {
|
||||||
|
|
||||||
OwnCloudVersion version = client.getOwnCloudVersion();
|
OwnCloudVersion version = client.getOwnCloudVersion();
|
||||||
boolean versionWithForbiddenChars =
|
boolean versionWithForbiddenChars =
|
||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
(version != null && version.isVersionWithForbiddenCharacters());
|
||||||
@ -101,9 +100,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult<String> result;
|
||||||
try {
|
try {
|
||||||
CopyMethod copyMethod = new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
CopyMethod copyMethod =
|
||||||
|
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
|
||||||
mOverwrite);
|
mOverwrite);
|
||||||
|
|
||||||
@ -113,16 +113,17 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
final int status = client.executeHttpMethod(copyMethod);
|
final int status = client.executeHttpMethod(copyMethod);
|
||||||
|
|
||||||
if (status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
if (status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
||||||
|
String fileRemoteId = copyMethod.getResponseHeader(HttpConstants.OC_FILE_REMOTE_ID);
|
||||||
result = new RemoteOperationResult<>(ResultCode.OK);
|
result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
|
result.setData(fileRemoteId);
|
||||||
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
||||||
|
|
||||||
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
||||||
|
|
||||||
/// 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
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
result = new RemoteOperationResult<>(copyMethod);
|
result = new RemoteOperationResult<>(copyMethod);
|
||||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user