The Process
- Select a video from the gallery using react-native-image-crop-picker
- Compress the video using react-native-compressor
- 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.