Skip to content

Commit d21f695

Browse files
Rajdeep Kaurfacebook-github-bot
Rajdeep Kaur
authored andcommitted
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
1 parent 5e68a98 commit d21f695

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/camera/CameraRollManager.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
8282

8383
private static final String SELECTION_BUCKET = Images.Media.BUCKET_DISPLAY_NAME + " = ?";
8484
private static final String SELECTION_DATE_TAKEN = Images.Media.DATE_TAKEN + " < ?";
85+
private static final String SELECTION_MEDIA_SIZE = Images.Media.SIZE + " < ?";
8586

8687
public CameraRollManager(ReactApplicationContext reactContext) {
8788
super(reactContext);
@@ -228,13 +229,21 @@ public void getPhotos(final ReadableMap params, final Promise promise) {
228229
String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
229230
String assetType =
230231
params.hasKey("assetType") ? params.getString("assetType") : ASSET_TYPE_PHOTOS;
232+
Integer maxSize = params.hasKey("maxSize") ? params.getInt("maxSize") : null;
231233
ReadableArray mimeTypes = params.hasKey("mimeTypes") ? params.getArray("mimeTypes") : null;
232234
if (params.hasKey("groupTypes")) {
233235
throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android");
234236
}
235237

236238
new GetMediaTask(
237-
getReactApplicationContext(), first, after, groupName, mimeTypes, assetType, promise)
239+
getReactApplicationContext(),
240+
first,
241+
after,
242+
groupName,
243+
mimeTypes,
244+
assetType,
245+
maxSize,
246+
promise)
238247
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
239248
}
240249

@@ -246,6 +255,7 @@ private static class GetMediaTask extends GuardedAsyncTask<Void, Void> {
246255
private final @Nullable ReadableArray mMimeTypes;
247256
private final Promise mPromise;
248257
private final String mAssetType;
258+
private final @Nullable Integer mMaxSize;
249259

250260
private GetMediaTask(
251261
ReactContext context,
@@ -254,6 +264,7 @@ private GetMediaTask(
254264
@Nullable String groupName,
255265
@Nullable ReadableArray mimeTypes,
256266
String assetType,
267+
@Nullable Integer maxSize,
257268
Promise promise) {
258269
super(context);
259270
mContext = context;
@@ -263,6 +274,7 @@ private GetMediaTask(
263274
mMimeTypes = mimeTypes;
264275
mPromise = promise;
265276
mAssetType = assetType;
277+
mMaxSize = maxSize;
266278
}
267279

268280
@Override
@@ -277,6 +289,10 @@ protected void doInBackgroundGuarded(Void... params) {
277289
selection.append(" AND " + SELECTION_BUCKET);
278290
selectionArgs.add(mGroupName);
279291
}
292+
if (mMaxSize != null) {
293+
selection.append(" AND " + SELECTION_MEDIA_SIZE);
294+
selectionArgs.add(mMaxSize.toString());
295+
}
280296

281297
switch (mAssetType) {
282298
case ASSET_TYPE_PHOTOS:

0 commit comments

Comments
 (0)