: Large base64 strings can cause "Out of Memory" (OOM) errors because they must be loaded entirely into RAM. For large files, it is better to download from a URL directly to the file system rather than converting to base64 first. Popular Libraries React Native save base64 image to Album - Stack Overflow
import ReactNativeBlobUtil from 'react-native-blob-util'; const saveBase64File = async (base64String, fileName) => { const dirs = ReactNativeBlobUtil.fs.dirs; const path = `${dirs.DownloadDir}/${fileName}`; // Android Download folder try { await ReactNativeBlobUtil.fs.writeFile(path, base64String, 'base64'); console.log('File saved to:', path); } catch (err) { console.error(err); } }; Use code with caution. Platform-Specific Considerations download base64 file react native
In non-Expo projects, react-native-blob-util (a maintained fork of rn-fetch-blob ) is the industry standard for handling binary data. npm install react-native-blob-util cd ios && pod install Use code with caution. Step 2: Implementation javascript : Large base64 strings can cause "Out of
: On iOS, files are typically saved to an app-private directory first. Use Sharing.shareAsync or ReactNativeBlobUtil.ios.previewDocument to let users move the file to their Files app or iCloud . Use Sharing
The implementation depends on whether you are using or the React Native Bare Workflow . 1. Using Expo ( expo-file-system )
import * as FileSystem from 'expo-file-system'; import * as Sharing from 'expo-sharing'; const downloadBase64 = async (base64String, fileName) => { // Remove header (e.g., "data:application/pdf;base64,") if present const base64Data = base64String.replace(/^data:.*,/, ''); const fileUri = `${FileSystem.documentDirectory}${fileName}`; try { await FileSystem.writeAsStringAsync(fileUri, base64Data, { encoding: FileSystem.EncodingType.Base64, }); // Prompt user to save or share the file if (await Sharing.isAvailableAsync()) { await Sharing.shareAsync(fileUri); } } catch (error) { console.error("Download error:", error); } }; Use code with caution.
: For Android 10 and below, you must add WRITE_EXTERNAL_STORAGE to your AndroidManifest.xml . Modern versions often require using the Storage Access Framework (SAF) via FileSystem.StorageAccessFramework to let users pick a destination folder.