Return-Path: X-Original-To: apmail-cordova-issues-archive@minotaur.apache.org Delivered-To: apmail-cordova-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DCE6618D57 for ; Thu, 15 Oct 2015 19:11:05 +0000 (UTC) Received: (qmail 27559 invoked by uid 500); 15 Oct 2015 19:11:05 -0000 Delivered-To: apmail-cordova-issues-archive@cordova.apache.org Received: (qmail 27523 invoked by uid 500); 15 Oct 2015 19:11:05 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 27508 invoked by uid 99); 15 Oct 2015 19:11:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2015 19:11:05 +0000 Date: Thu, 15 Oct 2015 19:11:05 +0000 (UTC) From: "Leonel Gayard (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (CB-9810) Mismatch between results of resolveLocalFileSystemURL and FileReader, throws error. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-9810?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Leonel Gayard updated CB-9810: ------------------------------ Description: h2. 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|http://www.w3.org/TR/2011/WD-file-system-api-20110419/#widl-LocalFileSystem-resolveLocalFileSystemURL] and [FileReader|http://www.w3.org/TR/FileAPI/#APIASynch]. h2. Possible causes ? It seems the fileEntry object is created inside the Java code, as a JSONObject (method [Filesystem#makeEntryForURL|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/src/android/Filesystem.java#L61]; therefore it does not implement the Javascript interfaces File or Blob. h2. Possible solution ? Looking at the source of [FileReader.js|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L130], 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|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L88] 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. h2. 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. was: h2. 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|http://www.w3.org/TR/2011/WD-file-system-api-20110419/#widl-LocalFileSystem-resolveLocalFileSystemURL] and [FileReader|http://www.w3.org/TR/FileAPI/#APIASynch]. h2. Possible causes ? It seems the fileEntry object is created inside the Java code, as a JSONObject (method [Filesystem#makeEntryForURL|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/src/android/Filesystem.java#L61]; therefore it does not implement the Javascript interfaces File or Blob. h2. Possible solution ? Looking at the source of [FileReader.js|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L130], 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|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L88] 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. > Mismatch between results of resolveLocalFileSystemURL and FileReader, throws error. > ----------------------------------------------------------------------------------- > > Key: CB-9810 > URL: https://issues.apache.org/jira/browse/CB-9810 > Project: Apache Cordova > Issue Type: Bug > Components: Plugin File > Affects Versions: 3.0.0 > Environment: Android SDK 22 > Tested on an LG Nexus, Android 5.0.1 > Reporter: Leonel Gayard > > h2. 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|http://www.w3.org/TR/2011/WD-file-system-api-20110419/#widl-LocalFileSystem-resolveLocalFileSystemURL] and [FileReader|http://www.w3.org/TR/FileAPI/#APIASynch]. > h2. Possible causes ? > It seems the fileEntry object is created inside the Java code, as a JSONObject (method [Filesystem#makeEntryForURL|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/src/android/Filesystem.java#L61]; therefore it does not implement the Javascript interfaces File or Blob. > h2. Possible solution ? > Looking at the source of [FileReader.js|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L130], 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|https://github.com/apache/cordova-plugin-file/blob/r3.0.0/www/FileReader.js#L88] 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. > h2. 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. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org