From fbae2a918536b733cc0f0dd4f82059450b5049ac Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 16 Oct 2021 15:52:12 -0400 Subject: [PATCH] Propagate MIME type information (for SVG upload previews) --- assets/js/upload.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/js/upload.js b/assets/js/upload.js index 4df7c9a7..8f00903f 100644 --- a/assets/js/upload.js +++ b/assets/js/upload.js @@ -14,14 +14,14 @@ function scrapeUrl(url) { .then(response => response.json()); } -function elementForEmbeddedImage({ camo_url }) { +function elementForEmbeddedImage({ camo_url, type }) { // The upload was fetched from the scraper and is a path name if (typeof camo_url === 'string') { return makeEl('img', { className: 'scraper-preview--image', src: camo_url }); } // The upload was fetched from a file input and is an ArrayBuffer - const objectUrl = URL.createObjectURL(new Blob([camo_url])); + const objectUrl = URL.createObjectURL(new Blob([camo_url], { type })); const tagName = new DataView(camo_url).getUint32(0) === MATROSKA_MAGIC ? 'video' : 'img'; return makeEl(tagName, { className: 'scraper-preview--image', src: objectUrl }); } @@ -75,6 +75,7 @@ function setupImageUpload() { reader.addEventListener('load', event => { showImages([{ camo_url: event.target.result, + type: fileField.files[0].type }]); // Clear any currently cached data, because the file field