Overview
REACT-NATIVE-COMPRESSOR is a react-native package that allows users to compress images, videos, and audio before uploading, similar to the compression algorithm used in WhatsApp. The package offers the benefit of achieving the same compression quality as WhatsApp without the need to know the compression algorithm, and it is lightweight, adding only around 50 KB to the APK size.
Features
- Image Compression: Compress images automatically like WhatsApp or manually with specified options.
- Video Compression: Compress videos automatically like WhatsApp or manually based on user-defined settings.
- Audio Compression: Offers background uploads and the ability to cancel uploads, making it convenient for managing audio files during uploads.
- Utility Functions: Includes features for creating video thumbnails, clearing cache, retrieving metadata of images and videos, and fetching real or temporary file paths.
Installation
Managed Expo
- Add the Compressor plugin to your Expo config (app.json, app.config.json or app.config.js).
- Compile the modifications by building a new binary with EAS.
Automatic Linking (for React Native >= 0.60 only)
- No manual linking required for React Native versions 0.60 or higher.
Manual Installation
iOS
- In Xcode, open Podfile and add
pod 'react-native-compressor', :path => '../node_modules/react-native-compressor'. - Run
pod installinside the ios folder. - Build the project (Cmd+R).
Android
- Open
android/app/src/main/java/[...]/MainActivity.java. - Add
import com.reactnativecompressor.CompressorPackage;to the imports. - Include
new CompressorPackage()in the list returned by thegetPackages()method. - Update
android/settings.gradleandandroid/app/build.gradlewith the provided lines.
Summary
REACT-NATIVE-COMPRESSOR is a powerful package for React Native developers looking to compress images, videos, and audio files before uploading, mimicking the compression quality of WhatsApp. With its lightweight design and comprehensive features, it offers an efficient solution for managing media uploads in mobile applications.