From c0ad7635f2864533226bb13a74e0cc0962b64b53 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 14 Feb 2018 09:29:37 -0800 Subject: [PATCH] change saveFile. attempting to fix for iOS --- app/utils.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/utils.js b/app/utils.js index e6d8d27b..b51906b1 100644 --- a/app/utils.js +++ b/app/utils.js @@ -142,19 +142,29 @@ function fadeOut(id) { } function saveFile(file) { + const reader = new FileReader(); const dataView = new DataView(file.plaintext); const blob = new Blob([dataView], { type: file.type }); - const downloadUrl = URL.createObjectURL(blob); if (window.navigator.msSaveBlob) { return window.navigator.msSaveBlob(blob, file.name); } - const a = document.createElement('a'); - a.href = downloadUrl; - a.download = file.name; - document.body.appendChild(a); - a.click(); - URL.revokeObjectURL(downloadUrl); + reader.addEventListener('loadend', function() { + if (reader.result) { + const a = document.createElement('a'); + a.href = reader.result; + a.download = file.name; + 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) {