Below code i am using for download pdf file from url. For Android it is working fine. when it is coming to iOS it is not downloading properly. it is showing just bytes only.
const downloadDir = Platform.OS === 'android' ? RNFS.DownloadDirectoryPath : RNFS.DocumentDirectoryPath; const localFilePath =${downloadDir}/${fileName}; ![Simulator Screenshot - iPhone 15 - 2024-10-24 at 14 17 31](https://github.com/user-attachments/assets/14fa6bd6-f509-43f8-bf5a-4e748bd0bf09) RNFS.downloadFile({ fromUrl: base64String, toFile: localFilePath, }) .promise.then(() => { Alert.alert( 'Download complete', 'File has been downloaded successfully', ); console.log('File downloaded to:', localFilePath); // Open the file using any viewer (if needed) openFile(localFilePath); }) .catch(error => { console.error('Download failed:', error); Alert.alert('Download failed', 'Unable to download the file.'); });
const openFile = (filePath) => { FileViewer.open(filePath) .then(() => { console.log('File opened successfully'); }) .catch((error) => { console.error('Failed to open file:', error); }); };
can anyone please help me on this. Thanks in advance.
HI,
Below code i am using for download pdf file from url. For Android it is working fine. when it is coming to iOS it is not downloading properly. it is showing just bytes only.
const downloadDir = Platform.OS === 'android' ? RNFS.DownloadDirectoryPath : RNFS.DocumentDirectoryPath; const localFilePath =
${downloadDir}/${fileName}; ![Simulator Screenshot - iPhone 15 - 2024-10-24 at 14 17 31](https://github.com/user-attachments/assets/14fa6bd6-f509-43f8-bf5a-4e748bd0bf09) RNFS.downloadFile({ fromUrl: base64String, toFile: localFilePath, }) .promise.then(() => { Alert.alert( 'Download complete', 'File has been downloaded successfully', ); console.log('File downloaded to:', localFilePath); // Open the file using any viewer (if needed) openFile(localFilePath); }) .catch(error => { console.error('Download failed:', error); Alert.alert('Download failed', 'Unable to download the file.'); });
const openFile = (filePath) => { FileViewer.open(filePath) .then(() => { console.log('File opened successfully'); }) .catch((error) => { console.error('Failed to open file:', error); }); };
can anyone please help me on this. Thanks in advance.