無法在 iPhone 或 iPad pro ios12 上的 safari 瀏覽器中下載 PDF



我的网络应用程序中有PDF下载功能。它适用于所有浏览器和 iOS11 运行良好,但它不适用于 safari 浏览器和移动设备或 iod pro 上的 ios12。 我得到以下错误 -WebKitBlobResource 错误 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)
})
}
}

当我们在新的url选项卡中打开pdf时,该文件不存在,但它只是存储在浏览器中的缓存。因此,当我们生成 blob 并重定向到当前选项卡以指向生成的 blob URL 时,我们会丢失缓存。 因此,在新窗口中打开网址会有所帮助。

let url = window.URL.createObjectURL(blob);
window.open(url, "_blank");

最新更新