Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript readAsDataurl is not a function

In Gecko/Firefox I got the error message:

TypeError: fr.readAsDataurl is not a function

Using the following JavaScript:

var fr = new FileReader();
fr.readAsDataURL(files[i]);
like image 232
John Avatar asked May 16 '15 06:05

John


1 Answers

As it turns out someone at Mozilla created the deprecated method readAsDataurl with the improper letter casing and since JavaScript is case sensitive I simply had to use the readAsDataURL method (uppercase URL):

if (fr.readAsDataURL) {fr.readAsDataURL(files[i]);}
else if (fr.readAsDataurl) {fr.readAsDataurl(files[i]);}

Note that the standard/proper casing method is detected first. If you want your code to work as quickly as possible performance will improve over time as standards support improves.

like image 154
John Avatar answered Oct 19 '22 23:10

John