Open lamaji opened 3 years ago
@lamaji Did you tried adding appendExt
option?
let options = {
fileCache: true,
appendExt: 'pdf',
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
path: dirToSave + "/filename.pdf",
description: 'PDF',
mime: 'application/pdf',
}
}
Latest working soln
const actualDownload = () => {
const { dirs } = RNFetchBlob.fs;
const dirToSave = Platform.OS == 'ios' ? dirs.DocumentDir : dirs.DownloadDir
const configfb = {
fileCache: true,
useDownloadManager: true,
notification: true,
mediaScannable: true,
title: pdfInfo.pdf,
path: `${dirToSave}/${pdfInfo.pdf}`,
}
const configOptions = Platform.select({
ios: {
fileCache: configfb.fileCache,
title: configfb.title,
path: configfb.path,
appendExt: 'pdf',
},
android: configfb,
});
console.log('The file saved to 23233', configfb, dirs);
RNFetchBlob.config(configOptions)
.fetch('GET', `https://aquatherm.s3.ap-south-1.amazonaws.com/pdfs/${pdfInfo.pdf}`, {})
.then((res) => {
if (Platform.OS === "ios") {
RNFetchBlob.fs.writeFile(configfb.path, res.data, 'base64');
RNFetchBlob.ios.previewDocument(configfb.path);
}
setisdownloaded(false)
if (Platform.OS == 'android') {
showSnackbar('File downloaded');
}
console.log('The file saved to ', res);
})
.catch((e) => {
setisdownloaded(true)
showSnackbar(e.message);
console.log('The file saved to ERROR', e.message)
});
}
@Ajmal0197 How would you go about doing this in a for loop where you're getting multiple files one after another?
@Ajmal0197 How would you go about doing this in a for loop where you're getting multiple files one after another?
Use forEach or map i think
RN version
0.61.2
Library version
0.12.0
My Code
Issue
download not working on iOS for files without extension with error message "protocol error" but works on android if I put a file url like this https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf it works fine.