|
18 | 18 | import com.owncloud.android.lib.common.operations.OperationCancelledException;
|
19 | 19 | import com.owncloud.android.lib.common.operations.RemoteOperation;
|
20 | 20 | import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
| 21 | +import com.owncloud.android.lib.common.utils.Log_OC; |
21 | 22 |
|
22 | 23 | import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
|
23 | 24 | import org.apache.commons.httpclient.Header;
|
|
32 | 33 | import java.util.Set;
|
33 | 34 | import java.util.concurrent.atomic.AtomicBoolean;
|
34 | 35 |
|
| 36 | +import java.io.FileInputStream; |
| 37 | +import java.security.DigestInputStream; |
| 38 | +import java.security.MessageDigest; |
| 39 | +import java.security.NoSuchAlgorithmException; |
| 40 | +import java.math.BigInteger; |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
35 | 45 | /**
|
36 | 46 | * Remote operation performing the upload of a remote file to the ownCloud server.
|
37 | 47 | *
|
@@ -211,6 +221,24 @@ protected RemoteOperationResult<String> uploadFile(OwnCloudClient client) throws
|
211 | 221 | }
|
212 | 222 |
|
213 | 223 | putMethod.setRequestEntity(entity);
|
| 224 | + |
| 225 | + try { |
| 226 | + MessageDigest md = MessageDigest.getInstance("SHA-256"); |
| 227 | + |
| 228 | + try (FileInputStream fis = new FileInputStream(f); |
| 229 | + DigestInputStream dis = new DigestInputStream(fis, md)) { |
| 230 | + byte[] buffer = new byte[8192]; |
| 231 | + while (dis.read(buffer) != -1) { |
| 232 | + // digest is updated by reading |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + String Hash = String.format("%064x", new BigInteger(1, md.digest())); |
| 237 | + putMethod.addRequestHeader("X-Content-Hash", Hash); |
| 238 | + } catch (Exception e) { |
| 239 | + Log_OC.w(this, "Could not compute chunk hash"); |
| 240 | + } |
| 241 | + |
214 | 242 | status = client.executeMethod(putMethod);
|
215 | 243 |
|
216 | 244 | result = new RemoteOperationResult<>(isSuccess(status), putMethod);
|
|
0 commit comments