Question

I am trying to read the content of a file into an array to be processed. Here is my attempt try and get the data of the file into a variable:

var theFile = document.getElementById("getFile");
var fileVal = theFile.files[0];
var dataFromFile = fileVal.getAsDataURL();
alert(dataFromFile);

But where I try to pass dataAsUrl to the dataFromFile variable it gives me the following error: Uncaught TypeError: undefined is not a function.

As a side note, this is part of a game project where we are only aloud to use pure JavaScript.

Was it helpful?

Solution

This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

The getAsDataURL provides a data: URL that encodes the entire contents of the referenced file.

Note: This method is obsolete; you should use the FileReader method readAsDataURL() instead.

Here is the live example.. jsfiddle.net/fKQDL/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top