Not sure what your $scope , but gives it an edge.
As you use webkitGetAsEntry() , I assume this is for Chrome. In appearance, your code should give you an error. If it is not, there is a possibility that you have omitted. Usually you should get something like:
Uncaught TypeError: Failed to execute 'readAsBinaryString' in 'FileReader': argument is not a block.
in your $scope.parse function.
There are a few questions. First, you probably read the files as text , not as a binary string. Secondly, readAsBinaryString() deprecated, use readAsArrayBuffer() if you want to read binary data.
In addition, webkitGetAsEntry() returns a FileEntry , so you should get the error mentioned above. To read a file you can usually do:
$scope.files[i].file(success_call_back, [error_call_back]);
For instance:
function my_parser(file) { var fileReader = new FileReader(); fileReader.onload = function (e) { console.log(fileReader.result); }; fileReader.onerror = function(err) { console.log(err); }; console.log('Read', file);
This will give you a File object as an argument to my_parser() . Then you can usually check .type and use the appropriate read function. (Although remember the slack in the MIME type. Like in: do not rely on it, but use it as a hint.)
if (file.type.match(/application\/javascript|text\/.*/)) { // Use text read } else if (file.type.match(/^image\/.*/)) { // Use binary read, read as dataURL etc. } else ...
source share