Open bony06aug opened 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')
});
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)
});
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') });
❤️❤️❤️
can you share the exact flow of downloading pdf in ios and showing option to save and share the pdf?