Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Can't open files in Firefox #8

Open
LinoLinux opened this Issue · 2 comments

3 participants

@LinoLinux

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
            };
            reader.readAsText(file,'ISO-8859-1');
        },errorHandler);
    }, 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
Owner

Can you attach a reproducible mini test case?

@janotav

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.