Propagate MIME type information (for SVG upload previews)

This commit is contained in:
byte[] 2021-10-16 15:52:12 -04:00
parent 08b4889b31
commit fbae2a9185

View file

@ -14,14 +14,14 @@ function scrapeUrl(url) {
.then(response => response.json()); .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 // The upload was fetched from the scraper and is a path name
if (typeof camo_url === 'string') { if (typeof camo_url === 'string') {
return makeEl('img', { className: 'scraper-preview--image', src: camo_url }); return makeEl('img', { className: 'scraper-preview--image', src: camo_url });
} }
// The upload was fetched from a file input and is an ArrayBuffer // 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'; const tagName = new DataView(camo_url).getUint32(0) === MATROSKA_MAGIC ? 'video' : 'img';
return makeEl(tagName, { className: 'scraper-preview--image', src: objectUrl }); return makeEl(tagName, { className: 'scraper-preview--image', src: objectUrl });
} }
@ -75,6 +75,7 @@ function setupImageUpload() {
reader.addEventListener('load', event => { reader.addEventListener('load', event => {
showImages([{ showImages([{
camo_url: event.target.result, camo_url: event.target.result,
type: fileField.files[0].type
}]); }]);
// Clear any currently cached data, because the file field // Clear any currently cached data, because the file field