Trigger download of the image file in a hacky way

Apparently this is the Recommended Approach for doing this - you create an <a> element,
set its attributes, then temporarily add it to the page and click() it.

The downloads.download() api we found earlier is exclusive to Chrome Apps.
pull/297/head
Mike Lang 2 years ago committed by Mike Lang
parent adb6e2ae10
commit 0681902789

@ -450,6 +450,16 @@ function downloadFrame() {
const url = `/frame/${globalStreamName}/source.png?timestamp=${wubloaderTimeFromDateTime(dateTime)}`; const url = `/frame/${globalStreamName}/source.png?timestamp=${wubloaderTimeFromDateTime(dateTime)}`;
// Avoid : as it causes problems on Windows // Avoid : as it causes problems on Windows
const filename = `${dateTime.toFormat("yyyy-LL-dd'T'HH-mm-ss.SSS")}.png`; const filename = `${dateTime.toFormat("yyyy-LL-dd'T'HH-mm-ss.SSS")}.png`;
// TODO REPLACE WITH CORRECT CALL triggerDownload(url, filename);
console.log(`Would download ${url} as ${filename}`); }
function triggerDownload(url, filename) {
// URL must be same-origin.
const link = document.createElement('a');
link.setAttribute('download', filename);
link.href = url;
link.setAttribute('target', '_blank');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} }

Loading…
Cancel
Save