Skip to content

Commit

Permalink
[#443] Set content length, ensure upload stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Inigo Lopez de Heredia committed May 31, 2016
1 parent a313ede commit 324710c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/org/akvo/flow/api/S3Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void get(String objectKey, File dst) throws IOException {

public boolean put(String objectKey, File file, String type, boolean isPublic) throws IOException {
// Get date and signature
final int size = (int)file.length();// long version was added on API level 19
final byte[] rawMd5 = FileUtil.getMD5Checksum(file);
final String md5Base64 = Base64.encodeToString(rawMd5, Base64.NO_WRAP);
final String md5Hex = FileUtil.hexMd5(rawMd5);
Expand All @@ -142,6 +143,7 @@ public boolean put(String objectKey, File file, String type, boolean isPublic) t
try {
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(size);
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-MD5", md5Base64);
conn.setRequestProperty("Content-Type", type);
Expand Down

0 comments on commit 324710c

Please sign in to comment.