Merge pull request #1508 from matrix-org/dbkr/image_objecturl
Use object URLs to load Files in to images
This commit is contained in:
commit
bd982cf0ae
1 changed files with 7 additions and 13 deletions
|
@ -99,23 +99,17 @@ function loadImageElement(imageFile) {
|
|||
|
||||
// Load the file into an html element
|
||||
const img = document.createElement("img");
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
img.src = e.target.result;
|
||||
const objectUrl = URL.createObjectURL(imageFile);
|
||||
img.src = objectUrl;
|
||||
|
||||
// Once ready, create a thumbnail
|
||||
img.onload = function() {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
deferred.resolve(img);
|
||||
};
|
||||
img.onerror = function(e) {
|
||||
deferred.reject(e);
|
||||
};
|
||||
};
|
||||
reader.onerror = function(e) {
|
||||
deferred.reject(e);
|
||||
};
|
||||
reader.readAsDataURL(imageFile);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue