Skip to content

Commit a7cf674

Browse files
added alternative image loading with FileReader when URL API is not available
1 parent a0694bc commit a7cf674

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

v3/src/loader/filetypes/ImageFile.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ var ImageFile = new Class({
5656

5757
this.data.onload = function ()
5858
{
59-
URL.revokeObjectURL(_this.data.src);
59+
if(URL)
60+
{
61+
URL.revokeObjectURL(_this.data.src);
62+
}
6063

6164
_this.onComplete();
6265

@@ -65,14 +68,40 @@ var ImageFile = new Class({
6568

6669
this.data.onerror = function ()
6770
{
68-
URL.revokeObjectURL(_this.data.src);
71+
if(URL)
72+
{
73+
URL.revokeObjectURL(_this.data.src);
74+
}
6975

7076
_this.state = CONST.FILE_ERRORED;
7177

7278
callback(_this);
7379
};
7480

75-
this.data.src = URL.createObjectURL(this.xhrLoader.response);
81+
if(URL)
82+
{
83+
this.data.src = URL.createObjectURL(this.xhrLoader.response);
84+
}
85+
else
86+
{
87+
var reader = new FileReader();
88+
89+
reader.onload = function()
90+
{
91+
delete _this.data.crossOrigin;
92+
_this.data.src = 'data:' + (_this.xhrLoader.response.type || 'image/png') + ';base64,' + reader.result.split(',')[1];
93+
};
94+
95+
reader.onerror = function ()
96+
{
97+
_this.state = CONST.FILE_ERRORED;
98+
99+
callback(_this);
100+
};
101+
102+
reader.readAsDataURL(this.xhrLoader.response);
103+
}
104+
76105
}
77106

78107
});

0 commit comments

Comments
 (0)