cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vladimir Avdonin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CB-3030) FileReader.readAsText fails with JSON error
Date Fri, 12 Apr 2013 21:32:15 GMT

     [ https://issues.apache.org/jira/browse/CB-3030?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Vladimir Avdonin updated CB-3030:
---------------------------------

    Attachment: index.html

Test program. Expected result: "Success" in console log when any file is present in /mnt/sdcard.
Ectual result: "Error JSON error" in console log.
                
> FileReader.readAsText fails with JSON error
> -------------------------------------------
>
>                 Key: CB-3030
>                 URL: https://issues.apache.org/jira/browse/CB-3030
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: Master
>            Reporter: Vladimir Avdonin
>            Assignee: Joe Bowser
>         Attachments: index.html
>
>
> When called to read the whole file readAsText fails with "JASON error". exception is
thrown from JSONArray.get(int), called from FileUtils.java:113 from the following code:
> int start = args.getInt(2);
> The reason is args at this point does not have 2 elements. It appears that readAsText
expects start and stop arguments to be always present, while caller in cordova.js only adds
these arguments when not full file is read. readAsDataURL has the same problem.
> Below is test program:
> -------------------------------index.html----------------------
> <!DOCTYPE html>
> <html>
>     <head>
>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>         <meta name="format-detection" content="telephone=no" />
>         <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1,
minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
>         <link rel="stylesheet" type="text/css" href="css/index.css" />
>         <title>Hello World</title>
>         <script src="cordova-2.5.0.js"></script>
>     </head>
>     <body>
>         <div>
>         	Testing
>         </div>
>         <script type="text/javascript">
>         function onDeviceReady() {
>             window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
>             	function(fs) {
>             		var dr = fs.root.createReader();
>             		dr.readEntries(
>             			function(entries) {
>             				for (var i=0; i<entries.length; i++) {
>             					var e = entries[i];
>             					if (e.isFile) {
>             						e.file(
>             							function(file) {
> 											var fr = new FileReader();
> 											fr.onloadend = function(evt) {
> 												var fr = evt.target;
> 												if (fr.result === null) {
> 													var msg = "Error "+ fr.error.code;
> 													console.log(msg);
> 												} else {
> 													console.log("Success");
> 												}
> 											};
> 											fr.readAsText(file);
>             							}
> 									);
> 									break;
>             					}
>             				}
>             			}
> 					);
> 				}
> 			);
> 		}
> 		document.addEventListener('deviceready', onDeviceReady, false);
>         </script>
>     </body>
> </html>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message