Skip to content

Commit

Permalink
Sardine: Add additional "put" method (with lock token)
Browse files Browse the repository at this point in the history
  • Loading branch information
rt1shnik committed Feb 5, 2020
1 parent 8ad210b commit b9127c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/thegrizzlylabs/sardineandroid/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ public interface Sardine
*/
void put(String url, File localFile, String contentType, boolean expectContinue) throws IOException;


/**
* Uses <code>PUT</code> to upload file to a server with specific contentType.
* Repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname
* @param localFile local file to send
* @param contentType MIME type to add to the HTTP request header
* @param expectContinue Enable <code>Expect: continue</code> header for <code>PUT</code> requests.
* @param lockToken A lock token is a type of state token that identifies a particular lock.
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, File localFile, String contentType, boolean expectContinue, String lockToken) throws IOException;

/**
* Delete a resource using HTTP <code>DELETE</code> at the specified url
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.thegrizzlylabs.sardineandroid.impl;

import android.text.TextUtils;

import com.thegrizzlylabs.sardineandroid.DavAce;
import com.thegrizzlylabs.sardineandroid.DavAcl;
import com.thegrizzlylabs.sardineandroid.DavPrincipal;
Expand Down Expand Up @@ -302,12 +304,20 @@ public void put(String url, File localFile, String contentType) throws IOExcepti

@Override
public void put(String url, File localFile, String contentType, boolean expectContinue) throws IOException {
put(url, localFile, contentType, expectContinue, null);
}

@Override
public void put(String url, File localFile, String contentType, boolean expectContinue, String lockToken) throws IOException {
MediaType mediaType = contentType == null ? null : MediaType.parse(contentType);
RequestBody requestBody = RequestBody.create(mediaType, localFile);
Headers.Builder headersBuilder = new Headers.Builder();
if (expectContinue) {
headersBuilder.add("Expect", "100-Continue");
}
if (!TextUtils.isEmpty(lockToken)) {
headersBuilder.add("If", "<" + url + "> (<" + lockToken + ">)");
}
put(url, requestBody, headersBuilder.build());
}

Expand Down

0 comments on commit b9127c2

Please sign in to comment.