Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.0
-
None
-
tested on ios6 in emulator
Description
/////
//summary
////
using documentation, i'm trying to write than read a file
writing works
file is actually created on fs
when writing, everything goes fine until FileReader.readAsText which does nothing at all...
/////
//example code
////
<!DOCTYPE html>
<html>
<head>
<title>FileReader Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady()
function gotFS(fileSystem)
{ fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail); }function gotFileEntry(fileEntry)
{ fileEntry.file(gotFile, fail); }function gotFile(file)
{ readDataUrl(file); readAsText(file); } function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt)
;
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt)
;
reader.readAsText(file);
}
function fail(error)
{ console.log(error.code); }function gotFS_w(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry_w, fail);
}
function gotFileEntry_w(fileEntry) { fileEntry.createWriter(gotFileWriter, fail); }
function gotFileWriter(writer) {
writer.onwriteend = function(evt) { console.log("contents of file now 'some sample text'"); window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); };
writer.write("some sample text");
}
function fail(error) { console.log(error.code); }
</script>
</head>
<body>
<h1>Example</h1>
<p>Read File</p>
</body>
</html>
///////
/// log output
//////
2012-09-24 20:16:31.731 Diveboard[39848:c07] Multi-tasking -> Device: YES, App: YES
2012-09-24 20:16:31.745 Diveboard[39848:c07] Application windows are expected to have a root view controller at the end of application launch
2012-09-24 20:16:31.831 Diveboard[39848:c07] PluginResult:toJSONString -
2012-09-24 20:16:31.832 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('NetworkStatus0',
{"status":1,"message":"wifi","keepCallback":false});
2012-09-24 20:16:31.833 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":
,"keepCallback":false}
2012-09-24 20:16:31.833 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('Device1',{"status":1,"message":
,"keepCallback":false});
2012-09-24 20:16:31.840 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":{"name":"persistent","root":{"name":"Documents","isFile":false,"isDirectory":true,"fullPath":"/Users/alex/Library/Application Support/iPhone Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents"}},"keepCallback":false}
2012-09-24 20:16:31.841 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File2',{"status":1,"message":{"name":"persistent","root":{"name":"Documents","isFile":false,"isDirectory":true,"fullPath":"/Users/alex/Library/Application Support/iPhone Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents"}},"keepCallback":false});
2012-09-24 20:16:31.842 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":
,"keepCallback":false}
2012-09-24 20:16:31.842 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File3',{"status":1,"message":
,"keepCallback":false});
2012-09-24 20:16:31.843 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":
,"keepCallback":false}
2012-09-24 20:16:31.843 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File4',{"status":1,"message":
,"keepCallback":false});
2012-09-24 20:16:31.844 Diveboard[39848:c07] PluginResult:toJSONString -
2012-09-24 20:16:31.844 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File5',
{"status":1,"message":16,"keepCallback":false});
2012-09-24 20:16:31.845 Diveboard[39848:c07] [INFO] contents of file now 'some sample text'
2012-09-24 20:16:31.846 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":{"name":"persistent","root":{"name":"Documents","isFile":false,"isDirectory":true,"fullPath":"/Users/alex/Library/Application Support/iPhone Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents"}},"keepCallback":false}
2012-09-24 20:16:31.846 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File6',{"status":1,"message":{"name":"persistent","root":{"name":"Documents","isFile":false,"isDirectory":true,"fullPath":"/Users/alex/Library/Application Support/iPhone Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents"}},"keepCallback":false});
2012-09-24 20:16:31.847 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":
,"keepCallback":false}
2012-09-24 20:16:31.847 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File7',{"status":1,"message":
,"keepCallback":false});
2012-09-24 20:16:31.848 Diveboard[39848:c07] PluginResult:toJSONString - {"status":1,"message":
,"keepCallback":false}
2012-09-24 20:16:31.848 Diveboard[39848:c07] PluginResult toSuccessCallbackString: cordova.callbackSuccess('File8',{"status":1,"message":
,"keepCallback":false});