change saveFile. attempting to fix for iOS

This commit is contained in:
Danny Coates 2018-02-14 09:29:37 -08:00
parent a82688163e
commit c0ad7635f2
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 17 additions and 7 deletions

View File

@ -142,19 +142,29 @@ function fadeOut(id) {
} }
function saveFile(file) { function saveFile(file) {
const reader = new FileReader();
const dataView = new DataView(file.plaintext); const dataView = new DataView(file.plaintext);
const blob = new Blob([dataView], { type: file.type }); const blob = new Blob([dataView], { type: file.type });
const downloadUrl = URL.createObjectURL(blob);
if (window.navigator.msSaveBlob) { if (window.navigator.msSaveBlob) {
return window.navigator.msSaveBlob(blob, file.name); return window.navigator.msSaveBlob(blob, file.name);
} }
const a = document.createElement('a'); reader.addEventListener('loadend', function() {
a.href = downloadUrl; if (reader.result) {
a.download = file.name; const a = document.createElement('a');
document.body.appendChild(a); a.href = reader.result;
a.click(); a.download = file.name;
URL.revokeObjectURL(downloadUrl); document.body.appendChild(a);
a.click();
return;
}
if (reader.error) {
console.error(reader.error);
window.location.href = '/error';
//TODO
}
});
reader.readAsDataURL(blob);
} }
function openLinksInNewTab(links, should = true) { function openLinksInNewTab(links, should = true) {