Skip to content
Snippets Groups Projects
Unverified Commit 6260f9c0 authored by Benjamin Wheeler's avatar Benjamin Wheeler Committed by GitHub
Browse files

Merge pull request #5101 from LLK/file-download-safari

Allow some kind of downloading to work on iOS Safari
parents dd90ec86 28cda953
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,23 @@ export default (filename, blob) => { ...@@ -8,11 +8,23 @@ export default (filename, blob) => {
return; return;
} }
const url = window.URL.createObjectURL(blob); if ('download' in HTMLAnchorElement.prototype) {
downloadLink.href = url; const url = window.URL.createObjectURL(blob);
downloadLink.download = filename; downloadLink.href = url;
downloadLink.type = blob.type; downloadLink.download = filename;
downloadLink.click(); downloadLink.type = blob.type;
window.URL.revokeObjectURL(url); downloadLink.click();
document.body.removeChild(downloadLink); document.body.removeChild(downloadLink);
window.URL.revokeObjectURL(url);
} else {
// iOS Safari, open a new page and set href to data-uri
let popup = window.open('', '_blank');
const reader = new FileReader();
reader.onloadend = function () {
popup.location.href = reader.result;
popup = null;
};
reader.readAsDataURL(blob);
}
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment