1

The Process

  1. Select a video from the gallery using react-native-image-crop-picker
  2. Compress the video using react-native-compressor
  3. Upload video on S3

The problem

❌ Video compression does not work on Android

ERROR: android open failed: ENOENT (No such file or directory)

These are the Permissions I have in my android/app/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA"/>

✅ Images and video compression work correctly in IOS.

✅ Only Image compression worked correctly in Android.

The code for video compression

  const chooseVideoFromLibrary = async () => {
    const options: Options = {
      mediaType: 'video',
    };

    try {
      setIsUploading(true);
      const response = await ImagePicker.openPicker(options);
      //Compress video -----
      const compressedVideoPath = await Video.compress(
        response.path,
        {
          compressionMethod: 'manual',
          minimumFileSizeForCompress: 1,
        })
      console.log('****compressing/SUCCESS-- ', compressedVideoPath)
      const dataToSend = { ...response, path: compressedVideoPath }

      // This is another function to handle S3 Upload
      await handleS3Upload(dataToSend);
    } catch (error) {
      console.log('Error: ', error);
    } finally {
      setIsUploading(false);
    }
  };

Note

It seems that the error appears when trying to upload the compressed video to the S3, I think that this package react-native-compressor returns an incorrect path for the compressed video on Android.

Finally, I hope this is clear to you so that you can help. If you have any idea that could help, or if you have a better solution for video compression with react native please share it with me, I'll appreciate it.

bilalo
  • 129
  • 1
  • 1
  • 7

2 Answers2

0

I would like to suggest library react-native-video-proccesing.

ronak dholariya
  • 177
  • 1
  • 6
0

Not a complete answer In such cases, I suggest the user tries to insert console.log at multiple positions to find where code execution stops. Also, you can reduce sources of error by storing the file only locally when you just want to check the issue.

Yash Gada
  • 41
  • 4