joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 784 forks source link

ios Pdf download #409

Open bony06aug opened 5 years ago

bony06aug commented 5 years ago

can you share the exact flow of downloading pdf in ios and showing option to save and share the pdf?

jordanboaz commented 5 years ago

const { dirs } = rnFetch.fs;

const dirToSave = Platform.select({ ios: dirs.DocumentDir, android: dirs.DocumentDir }); const filePath = ${dirToSave}/FILENAME.ext;

rn-fetch-blob .fetch( 'GET', yoururl, { Authorization: bearer ${accessToken} } ) .then((res): void => { rnFetch.fs.writeFile(filePath, res.data, 'base64'); rnFetch.ios.previewDocument(filePath); }) .catch((errorMessage, statusCode): void => { console.log('error') });

ahmad6242 commented 5 years ago

I THINK , this code by @jbrmaiden1 is downloading the file but i cant see the file in the device ios. i have downloaded the Adobe pdf reader but still cant find the file. Maybe it is not working. Am i missing something?

const { dirs } = RNFetchBlob.fs; const dirToSave = Platform.select({ ios: dirs.DocumentDir, android: dirs.DocumentDir }); console.log('dirToSave', dirToSave) const filePath = dirToSave + '/' + Math.random().toString(36).substr(2, 5) + '.' + ext RNFetchBlob.fetch( 'GET', downloadURL, ) .then((res) => { console.log('one1', res) RNFetchBlob.fs.writeFile(filePath, res.data, 'base64').then((res) => { console.log('writeFile', res) }).catch((res) => { console.log('previewDocument', res) }) _this.setState({ spinner: false }, () => { _this.refs.modalFlash.showMessage({ message: translate('Success!'), description: translate('File Downloaded!'), type: "success", autoHide: true, animated: true, icon: 'auto', hideOnPress: true,

                        })
                    })
                })
                .catch((errorMessage, statusCode) => {
                    console.log('one2', errorMessage, statusCode)
                });
Rutvik17 commented 4 years ago

const { dirs } = rnFetch.fs;

const dirToSave = Platform.select({ ios: dirs.DocumentDir, android: dirs.DocumentDir }); const filePath = ${dirToSave}/FILENAME.ext;

rn-fetch-blob .fetch( 'GET', yoururl, { Authorization: bearer ${accessToken} } ) .then((res): void => { rnFetch.fs.writeFile(filePath, res.data, 'base64'); rnFetch.ios.previewDocument(filePath); }) .catch((errorMessage, statusCode): void => { console.log('error') });

❤️❤️❤️