mirror of https://github.com/vector-im/riot-web
Merge pull request #1508 from matrix-org/dbkr/image_objecturl
Use object URLs to load Files in to imagespull/21833/head
commit
bd982cf0ae
|
@ -99,23 +99,17 @@ function loadImageElement(imageFile) {
|
||||||
|
|
||||||
// Load the file into an html element
|
// Load the file into an html element
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
|
const objectUrl = URL.createObjectURL(imageFile);
|
||||||
|
img.src = objectUrl;
|
||||||
|
|
||||||
const reader = new FileReader();
|
// Once ready, create a thumbnail
|
||||||
reader.onload = function(e) {
|
img.onload = function() {
|
||||||
img.src = e.target.result;
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
deferred.resolve(img);
|
||||||
// Once ready, create a thumbnail
|
|
||||||
img.onload = function() {
|
|
||||||
deferred.resolve(img);
|
|
||||||
};
|
|
||||||
img.onerror = function(e) {
|
|
||||||
deferred.reject(e);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
reader.onerror = function(e) {
|
img.onerror = function(e) {
|
||||||
deferred.reject(e);
|
deferred.reject(e);
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(imageFile);
|
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue