From b74ad8634ba43f44d5b40dae6e7b9597d6b4f5e0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Oct 2017 17:16:52 +0100 Subject: [PATCH] Use object URLs to load Files in to images Fixes https://github.com/vector-im/riot-web/issues/5326 --- src/ContentMessages.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index 00728061a2..8d40b65124 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -99,23 +99,17 @@ function loadImageElement(imageFile) { // Load the file into an html element const img = document.createElement("img"); + const objectUrl = URL.createObjectURL(imageFile); + img.src = objectUrl; - const reader = new FileReader(); - reader.onload = function(e) { - img.src = e.target.result; - - // Once ready, create a thumbnail - img.onload = function() { - deferred.resolve(img); - }; - img.onerror = function(e) { - deferred.reject(e); - }; + // Once ready, create a thumbnail + img.onload = function() { + URL.revokeObjectURL(objectUrl); + deferred.resolve(img); }; - reader.onerror = function(e) { + img.onerror = function(e) { deferred.reject(e); }; - reader.readAsDataURL(imageFile); return deferred.promise; }