Skip to content
Permalink
Browse files
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
  • Loading branch information
Rajdeep Kaur authored and facebook-github-bot committed Sep 26, 2019
1 parent 5e68a98 commit d21f695edf367166a03af4c6e9376cd498b38665
Showing 1 changed file with 17 additions and 1 deletion.
@@ -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<Void, Void> {
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:

0 comments on commit d21f695

Please sign in to comment.