I am building an app that lets the user download a PDF file when he clicks on a button.
I use the library react-native-fetch-blob for this purpose.
It works well on Android.
On iOS, the console log tells me the download has worked well, but:
What is the right way to achieve what I want?
The solution thats worked for me in iOS was use RNFetchBlob.ios.openDocument function inside the then of fetch. This function open the file on the device file explorer where you have the option to download. Here is the code example:
downloadPDFiOS (uri) {
let uriSplitted = uri.split("/");
const fileName = uriSplitted.pop();
const dirs = RNFetchBlob.fs.dirs;
RNFetchBlob
.config({
path: dirs.DocumentDir + '/' + fileName,
fileCache: true,
})
.fetch('GET', uri, {
//some headers ..
})
.then((res) => {
RNFetchBlob.ios.openDocument(res.data);
})
.catch((e) => {
console.log('Error en el fetch: ', e);
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With