mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Use DavOCResource again
This commit is contained in:
		
							parent
							
								
									dae28aee48
								
							
						
					
					
						commit
						5d0362dc4d
					
				| @ -1 +1 @@ | ||||
| Subproject commit 980eb7ece17314f6c88f87319be1541c579c4b94 | ||||
| Subproject commit a149a3ff92a1149f02012086ed4de4b442efece5 | ||||
| @ -27,6 +27,7 @@ package com.owncloud.android.lib.refactor.operations; | ||||
| import com.owncloud.android.lib.refactor.OCContext; | ||||
| import com.owncloud.android.lib.refactor.RemoteOperation; | ||||
| 
 | ||||
| import at.bitfire.dav4android.DavOCResource; | ||||
| import at.bitfire.dav4android.DavResource; | ||||
| import at.bitfire.dav4android.PropertyUtils; | ||||
| import okhttp3.HttpUrl; | ||||
| @ -45,14 +46,15 @@ public class PropfindOperation extends RemoteOperation<DavResource> { | ||||
|     @Override | ||||
|     public Result exec() { | ||||
|         try { | ||||
|             final HttpUrl location = HttpUrl.parse(getWebDavHttpUrl("/").toString()); | ||||
|             final HttpUrl location = HttpUrl.parse(getWebDavHttpUrl(mRemotePath).toString()); | ||||
| 
 | ||||
|             DavResource davResource = new DavResource(getClient(), location); | ||||
|             davResource.propfind(1, PropertyUtils.INSTANCE.getAllPropSet()); | ||||
|             DavOCResource davOCResource = new DavOCResource(getClient(), location); | ||||
|             davOCResource.propfind(1, PropertyUtils.INSTANCE.getAllPropSet()); | ||||
| 
 | ||||
|             return new Result(OK, davOCResource); | ||||
| 
 | ||||
|             return new Result(OK, davResource); | ||||
|         } catch (Exception e) { | ||||
|             return new Result(e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -26,13 +26,11 @@ 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.DavResource; | ||||
| import at.bitfire.dav4android.DavOCResource; | ||||
| import okhttp3.MediaType; | ||||
| import okhttp3.Request; | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| import static com.owncloud.android.lib.refactor.RemoteOperationResult.ResultCode.OK; | ||||
| @ -42,11 +40,6 @@ import static com.owncloud.android.lib.refactor.RemoteOperationResult.ResultCode | ||||
|  */ | ||||
| public class UploadRemoteFileOperation extends RemoteOperation<Void> { | ||||
| 
 | ||||
|     private static final String CONTENT_TYPE_HEADER = "Content-Type"; | ||||
|     private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; | ||||
|     private static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; | ||||
|     private static final String IF_MATCH_HEADER = "If-Match"; | ||||
| 
 | ||||
|     private File mFileToUpload; | ||||
|     private String mRemotePath; | ||||
|     private String mMimeType; | ||||
| @ -71,20 +64,19 @@ public class UploadRemoteFileOperation extends RemoteOperation<Void> { | ||||
|             MediaType mediaType = MediaType.parse(mMimeType); | ||||
|             RequestBody requestBody = RequestBody.create(mediaType, mFileToUpload); | ||||
| 
 | ||||
|             DavResource davResource = new DavResource( | ||||
|                     getClient() | ||||
|                             .newBuilder() | ||||
|                             .addInterceptor(chain -> | ||||
|                                     chain.proceed( | ||||
|                                             addUploadHeaders(chain.request()) | ||||
|                                             .build())) | ||||
|                             .followRedirects(false) | ||||
|                             .build(), | ||||
|                     getWebDavHttpUrl(mRemotePath)); | ||||
|             DavOCResource davOCResource = new DavOCResource( | ||||
|                     getClient(), | ||||
|                     getWebDavHttpUrl(mRemotePath) | ||||
|             ); | ||||
| 
 | ||||
|             davResource.put(requestBody, | ||||
|             davOCResource.put( | ||||
|                     requestBody, | ||||
|                     null, | ||||
|                     false); | ||||
|                     false, | ||||
|                     "multipart/form-data", | ||||
|                     String.valueOf(mFileToUpload.length()), | ||||
|                     mFileLastModifTimestamp | ||||
|             ); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             return new Result(e); | ||||
| @ -92,19 +84,4 @@ public class UploadRemoteFileOperation extends RemoteOperation<Void> { | ||||
| 
 | ||||
|         return new Result(OK); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Add headers needed to upload a file | ||||
|      * @param request request in which include the headers | ||||
|      * @return request with upload headers | ||||
|      */ | ||||
|     private Request.Builder addUploadHeaders (Request request) { | ||||
| 
 | ||||
|         Request.Builder builder =  request.newBuilder(); | ||||
|         builder.addHeader(CONTENT_TYPE_HEADER, "multipart/form-data"); | ||||
|         builder.addHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(mFileToUpload.length())); | ||||
|         builder.addHeader(OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp); | ||||
| 
 | ||||
|         return builder; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user