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.OCContext; | ||||||
| import com.owncloud.android.lib.refactor.RemoteOperation; | import com.owncloud.android.lib.refactor.RemoteOperation; | ||||||
| 
 | 
 | ||||||
|  | import at.bitfire.dav4android.DavOCResource; | ||||||
| import at.bitfire.dav4android.DavResource; | import at.bitfire.dav4android.DavResource; | ||||||
| import at.bitfire.dav4android.PropertyUtils; | import at.bitfire.dav4android.PropertyUtils; | ||||||
| import okhttp3.HttpUrl; | import okhttp3.HttpUrl; | ||||||
| @ -45,12 +46,13 @@ public class PropfindOperation extends RemoteOperation<DavResource> { | |||||||
|     @Override |     @Override | ||||||
|     public Result exec() { |     public Result exec() { | ||||||
|         try { |         try { | ||||||
|             final HttpUrl location = HttpUrl.parse(getWebDavHttpUrl("/").toString()); |             final HttpUrl location = HttpUrl.parse(getWebDavHttpUrl(mRemotePath).toString()); | ||||||
| 
 | 
 | ||||||
|             DavResource davResource = new DavResource(getClient(), location); |             DavOCResource davOCResource = new DavOCResource(getClient(), location); | ||||||
|             davResource.propfind(1, PropertyUtils.INSTANCE.getAllPropSet()); |             davOCResource.propfind(1, PropertyUtils.INSTANCE.getAllPropSet()); | ||||||
|  | 
 | ||||||
|  |             return new Result(OK, davOCResource); | ||||||
| 
 | 
 | ||||||
|             return new Result(OK, davResource); |  | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             return new Result(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.OCContext; | ||||||
| import com.owncloud.android.lib.refactor.RemoteOperation; | import com.owncloud.android.lib.refactor.RemoteOperation; | ||||||
| import com.owncloud.android.lib.refactor.RemoteOperationResult; |  | ||||||
| 
 | 
 | ||||||
| import java.io.File; | import java.io.File; | ||||||
| 
 | 
 | ||||||
| import at.bitfire.dav4android.DavResource; | import at.bitfire.dav4android.DavOCResource; | ||||||
| import okhttp3.MediaType; | import okhttp3.MediaType; | ||||||
| import okhttp3.Request; |  | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| 
 | 
 | ||||||
| import static com.owncloud.android.lib.refactor.RemoteOperationResult.ResultCode.OK; | 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> { | 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 File mFileToUpload; | ||||||
|     private String mRemotePath; |     private String mRemotePath; | ||||||
|     private String mMimeType; |     private String mMimeType; | ||||||
| @ -71,20 +64,19 @@ public class UploadRemoteFileOperation extends RemoteOperation<Void> { | |||||||
|             MediaType mediaType = MediaType.parse(mMimeType); |             MediaType mediaType = MediaType.parse(mMimeType); | ||||||
|             RequestBody requestBody = RequestBody.create(mediaType, mFileToUpload); |             RequestBody requestBody = RequestBody.create(mediaType, mFileToUpload); | ||||||
| 
 | 
 | ||||||
|             DavResource davResource = new DavResource( |             DavOCResource davOCResource = new DavOCResource( | ||||||
|                     getClient() |                     getClient(), | ||||||
|                             .newBuilder() |                     getWebDavHttpUrl(mRemotePath) | ||||||
|                             .addInterceptor(chain -> |             ); | ||||||
|                                     chain.proceed( |  | ||||||
|                                             addUploadHeaders(chain.request()) |  | ||||||
|                                             .build())) |  | ||||||
|                             .followRedirects(false) |  | ||||||
|                             .build(), |  | ||||||
|                     getWebDavHttpUrl(mRemotePath)); |  | ||||||
| 
 | 
 | ||||||
|             davResource.put(requestBody, |             davOCResource.put( | ||||||
|  |                     requestBody, | ||||||
|                     null, |                     null, | ||||||
|                     false); |                     false, | ||||||
|  |                     "multipart/form-data", | ||||||
|  |                     String.valueOf(mFileToUpload.length()), | ||||||
|  |                     mFileLastModifTimestamp | ||||||
|  |             ); | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             return new Result(e); |             return new Result(e); | ||||||
| @ -92,19 +84,4 @@ public class UploadRemoteFileOperation extends RemoteOperation<Void> { | |||||||
| 
 | 
 | ||||||
|         return new Result(OK); |         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