diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-04-01 00:03:14 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-04-01 00:03:14 +0200 |
commit | 2549ce89b0fac2a41c4de61c42d76e521875717f (patch) | |
tree | 82c1276915d3be029e05015714e750fc48ca15ab /src/main/java/eu/siacs/conversations/persistance | |
parent | 74c496fe3ef544d45c94365799c061ddfe898330 (diff) |
check max http file size when attaching files
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 18c195f12..6e118ec22 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1,6 +1,8 @@ package eu.siacs.conversations.persistance; +import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -8,6 +10,7 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.net.Uri; import android.os.Environment; +import android.provider.OpenableColumns; import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; @@ -28,6 +31,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.Locale; import eu.siacs.conversations.Config; @@ -110,6 +114,24 @@ public class FileBackend { } } + public static long getFileSize(Context context, Uri uri) { + Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); + } else { + return -1; + } + } + + public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) { + for(Uri uri : uris) { + if (FileBackend.getFileSize(context, uri) > max) { + return false; + } + } + return true; + } + public static String getConversationsFileDirectory() { return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/"; } |