Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Can't open files in Firefox #8

marcoreni opened this Issue Nov 20, 2012 · 3 comments


None yet
4 participants

I'm trying to build an webapp to open some text files saved in the filesystem. and I decided to use this library to be able to use my app on FF17b (next step will be try to add IndexedDb Shim to enable WebSQL fallback).

My code works fine in Chrome, but I receive an error when I try to open a file on Firefox.

Here is my code:

function onInitFs(fs) {
    fs.root.getFile('/path/to/file.txt', {create: false}, function(fileEntry) {
        fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function (e) {
                //do something
    }, errorHandler);

and the error I receive is :NS_ERROR_FAILURE: Failure arg 0 [nsIDOMFileReader.readAsText]
The line the error refers to is reader.readAsText(file,'ISO-8859-1');

I tried some debugging in Firebug and I discovered that object "file" has correct "name" but size 0, empty type and null "blob_", and nothing more.

Am I doing something wrong or is it a problem with the library?


ebidel commented Jan 3, 2013

Can you attach a reproducible mini test case?

janotav commented Jun 26, 2013

I encountered the same issue for empty files. To me it seems that this is the culprit:

  // If we're returning a zero-length (empty) file, return the fake file obj.
  // Otherwise, return the native File object that we've stashed.
  var file = this.file_.blob_ == null ? this.file_ : this.file_.blob_;

The problem is that "this.file_" is later passed to the reader and not recognized by it (it's not the native File representation). It doesn't make terrible sense to read empty file, but semantically such operation is correct and in my case the operation is performed by 3rd party code so I cannot avoid it either.


Eeems commented Nov 25, 2015

I'm also running into this. I'm working around it for now by changing the line @janotav mentioned to the following.

var file = this.file_.blob_ == null ? new Blob([]) : this.file_.blob_;

There is probably a better way to do handling for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment