itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.97k stars 986 forks source link

Download issue in iOS #1243

Closed Aditya402 closed 4 weeks ago

Aditya402 commented 4 weeks ago

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); }); };

Simulator Screenshot - iPhone 15 - 2024-10-24 at 14 17 31 can anyone please help me on this. Thanks in advance.

Aditya402 commented 4 weeks ago

working fine now