Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9810

Mismatch between results of resolveLocalFileSystemURL and FileReader, throws error.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 3.0.0
    • None
    • cordova-plugin-file
    • None
    • Android SDK 22
      Tested on an LG Nexus, Android 5.0.1

    Description

      The problem

      When reading a file with resolveLocalFileSystemURL followed by FileReader.readAsText, the latter fails, with the error message Uncaught TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'.

      cordova-plugin-file provides these functions, which match the W3C APIs for File and File System: resolveLocalFileSystemURL and FileReader.

      Possible causes ?

      It seems the fileEntry object is created inside the Java code, as a JSONObject (method Filesystem#makeEntryForURL; therefore it does not implement the Javascript interfaces File or Blob.

      Possible solution ?

      Looking at the source of FileReader.js, it seems the FileReader implemented by the plugin delegates to the FileReader of the web view (at least, that's what the name of the variable suggests, `realReader`.

      Also, the function in file FileReader.js seems to rely on the attribute localURL of the file object, which is not part of the API.

      I made a quick hack on my local installation, to remove the call to the "real" FileReader, and use the one written in Java; this fixed the issue, and makes it possible to use FileReader.

      Tested on Android SDK 22, on an LG Nexus, Android 5.0.1.

      Example

      The repo at https://github.com/leonelag/proto-file-plugin has an example of an application trying to use the plugin to read and write files, and fails on Android.

      Attachments

        Activity

          People

            Unassigned Unassigned
            leonelag Leonel Gayard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: