I have PDF download functionality in my web app. It is working fine with all the browsers and iOS11 but it's not working on safari browser and ios12 on mobile or iod pro. I am getting below error - WebKitBlobResource error 1
export const downloadPDF = (downloadLink, fileName, trackId, productId, historyId) => {
return (dispatch) => {
return request.doGetAuth(downloadLink).then(response => {
let contentType = response.headers.get('content-type');
if (_.includes(contentType, 'application/json')) {
return response.json();
} else {
return response.blob();
}
}).then(blobby => {
if (!blobby.message) {
const blob = new Blob([blobby], {
type: 'application/pdf'
});
if (isIos()) {
if (!isCriOs()) {
// For ios
let url = window.URL.createObjectURL(blob);
dispatch(downloadReadyAction(url, fileName));
} else {
// if chrome
let reader = new FileReader();
reader.onload = function(e) {
dispatch(downloadReadyAction(reader.result, fileName));
}
reader.readAsDataURL(blob);
}
} else {
FileSaver.saveAs(blob, fileName);
}
}
}).catch(err => {
console.log('Problem downloading pdf from server ' + err)
})
}
}
Clear the Safari Cache An outdated browser cache can wreak havoc and cause all sorts of issues and might result in Safari not downloading files on your Mac. Check if deleting it makes a difference: Click Safari (in the menu bar) and select Preferences. Switch to the Advanced tab.
Open Safari and jump to the website you'd like to save. Tap the Share button at the bottom. At the top of the Share Sheet, tap Options > and choose PDF instead of Automatic, then tap Done.
If you receive a file via [Open in Browser] after entering a share-link in the Safari mobile web browser, it may be difficult to download the file, because the file that you want to download is a large file or the file has a file format or codec not supported by iOS.
To download a file in Safari, just tap on a download link on a website or tap and hold on a link and then tap Download Linked File (Figure B). Downloading a file in Safari on iOS or iPadOS is as easy as tapping and holding on a link and selecting Download Linked File.
When we open pdf in new url tab , The file doesn't exist but its only cache stored inside the browser. So when we generate the blob and redirect to current tab to point to the generated blob url, We lose the cache. So opening url in new window helps it.
let url = window.URL.createObjectURL(blob);
window.open(url, "_blank");
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