From d21f695edf367166a03af4c6e9376cd498b38665 Mon Sep 17 00:00:00 2001 From: Rajdeep Kaur Date: Thu, 26 Sep 2019 09:45:24 -0700 Subject: [PATCH] Limit size of video uploaded from camera roll in android Summary: Details in Task T53266042. AMA users are trying to upload video data of more than 300 MB which is causing spikes of server_err in the web tier. So i added check to retrive videos that have size < 100 MB. Reviewed By: furdei Differential Revision: D17544308 fbshipit-source-id: 5a1d1329b6b12656f1617bb8775e303c96d529cb --- .../modules/camera/CameraRollManager.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java b/ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java index b07abea106711f..b240a4f0432d05 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java @@ -82,6 +82,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule { private static final String SELECTION_BUCKET = Images.Media.BUCKET_DISPLAY_NAME + " = ?"; private static final String SELECTION_DATE_TAKEN = Images.Media.DATE_TAKEN + " < ?"; + private static final String SELECTION_MEDIA_SIZE = Images.Media.SIZE + " < ?"; public CameraRollManager(ReactApplicationContext reactContext) { super(reactContext); @@ -228,13 +229,21 @@ public void getPhotos(final ReadableMap params, final Promise promise) { String groupName = params.hasKey("groupName") ? params.getString("groupName") : null; String assetType = params.hasKey("assetType") ? params.getString("assetType") : ASSET_TYPE_PHOTOS; + Integer maxSize = params.hasKey("maxSize") ? params.getInt("maxSize") : null; ReadableArray mimeTypes = params.hasKey("mimeTypes") ? params.getArray("mimeTypes") : null; if (params.hasKey("groupTypes")) { throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android"); } new GetMediaTask( - getReactApplicationContext(), first, after, groupName, mimeTypes, assetType, promise) + getReactApplicationContext(), + first, + after, + groupName, + mimeTypes, + assetType, + maxSize, + promise) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -246,6 +255,7 @@ private static class GetMediaTask extends GuardedAsyncTask { private final @Nullable ReadableArray mMimeTypes; private final Promise mPromise; private final String mAssetType; + private final @Nullable Integer mMaxSize; private GetMediaTask( ReactContext context, @@ -254,6 +264,7 @@ private GetMediaTask( @Nullable String groupName, @Nullable ReadableArray mimeTypes, String assetType, + @Nullable Integer maxSize, Promise promise) { super(context); mContext = context; @@ -263,6 +274,7 @@ private GetMediaTask( mMimeTypes = mimeTypes; mPromise = promise; mAssetType = assetType; + mMaxSize = maxSize; } @Override @@ -277,6 +289,10 @@ protected void doInBackgroundGuarded(Void... params) { selection.append(" AND " + SELECTION_BUCKET); selectionArgs.add(mGroupName); } + if (mMaxSize != null) { + selection.append(" AND " + SELECTION_MEDIA_SIZE); + selectionArgs.add(mMaxSize.toString()); + } switch (mAssetType) { case ASSET_TYPE_PHOTOS: