1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-15 18:32:57 +00:00

Implement UploadRemoteFileOperation with dav4droid

This commit is contained in:
davigonz
2018-05-23 19:06:45 +02:00
parent 2ef51dd5f6
commit 75ce8e186f
5 changed files with 149 additions and 78 deletions
@@ -1,3 +1,27 @@
/* ownCloud Android Library is available under MIT license
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.refactor.operations;
import com.owncloud.android.lib.refactor.OCContext;
@@ -13,7 +37,6 @@ public class PropfindOperation extends RemoteOperation {
public PropfindOperation(OCContext context, String remotePath) {
super(context);
mRemotePath = remotePath;
}
@@ -1,44 +0,0 @@
package com.owncloud.android.lib.refactor.operations;
import com.owncloud.android.lib.refactor.OCContext;
import com.owncloud.android.lib.refactor.RemoteOperation;
import com.owncloud.android.lib.refactor.RemoteOperationResult;
import at.bitfire.dav4android.DavOCResource;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.PropertyUtils;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class PutOperation extends RemoteOperation {
private String mRemotePath;
private String mMimeType;
private String mTimeStamp;
public PutOperation(OCContext context, String remotePath, String mimetype, String timestamp) {
super(context);
mRemotePath = remotePath;
mMimeType = mimetype;
mTimeStamp = timestamp;
}
@Override
public RemoteOperationResult exec() {
try {
MediaType mediaType = MediaType.parse(mMimeType);
RequestBody requestBody = RequestBody.create(mediaType, mRemotePath);
DavOCResource davOCResource = new DavOCResource(getClient(), getWebDavHttpUrl(mRemotePath), null);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@@ -0,0 +1,81 @@
/* ownCloud Android Library is available under MIT license
* 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.refactor.operations;
import com.owncloud.android.lib.refactor.OCContext;
import com.owncloud.android.lib.refactor.RemoteOperation;
import com.owncloud.android.lib.refactor.RemoteOperationResult;
import java.io.File;
import at.bitfire.dav4android.DavOCResource;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class UploadRemoteFileOperation extends RemoteOperation {
private String mLocalPath;
private String mRemotePath;
private String mMimeType;
private String mFileLastModifTimestamp;
public UploadRemoteFileOperation(OCContext context, String localPath, String remotePath, String mimetype,
String fileLastModifTimestamp) {
super(context);
mLocalPath = localPath;
mRemotePath = remotePath;
mMimeType = mimetype;
mFileLastModifTimestamp = fileLastModifTimestamp;
}
@Override
public RemoteOperationResult exec() {
try {
File fileToUpload = new File(mLocalPath);
MediaType mediaType = MediaType.parse(mMimeType);
RequestBody requestBody = RequestBody.create(mediaType, fileToUpload);
DavOCResource davOCResource = new DavOCResource(
getClient(),
getWebDavHttpUrl(mRemotePath),
null);
davOCResource.put(requestBody,
null,
false,
"multipart/form-data",
String.valueOf(fileToUpload.length()),
mFileLastModifTimestamp);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}