Skip to content

Instantly share code, notes, and snippets.

@Saad-Bashar
Created September 25, 2022 06:05
Show Gist options
  • Select an option

  • Save Saad-Bashar/62781abe5699ad47864eb105958118d1 to your computer and use it in GitHub Desktop.

Select an option

Save Saad-Bashar/62781abe5699ad47864eb105958118d1 to your computer and use it in GitHub Desktop.
downloading pdf files in react native
const downloadFile = () => {
const source = "https://www.africau.edu/images/default/sample.pdf";
let dirs = ReactNativeBlobUtil.fs.dirs;
ReactNativeBlobUtil.config({
fileCache: true,
appendExt: 'pdf',
path: `${dirs.DocumentDir}/${fileName}`,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
title: fileName,
description: 'File downloaded by download manager.',
mime: 'application/pdf',
},
})
.fetch('GET', fileUrl)
.then((res) => {
// in iOS, we want to save our files by opening up the saveToFiles bottom sheet action.
// whereas in android, the download manager is handling the download for us.
if (Platform.OS === 'ios') {
const filePath = res.path();
let options = {
type: 'application/pdf',
url: filePath,
saveToFiles: true,
};
Share.open(options)
.then((resp) => console.log(resp))
.catch((err) => console.log(err));
}
})
.catch((err) => console.log('BLOB ERROR -> ', err));
};
@Moeed-Farooq
Copy link
Copy Markdown

@Saad-Bashar source and filename missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment