alexander casassovici created CB-1533:
-----------------------------------------
Summary: cannot read file
Key: CB-1533
URL: https://issues.apache.org/jira/browse/CB-1533
Project: Apache Cordova
Issue Type: Bug
Components: iOS
Affects Versions: 2.0.0
Environment: tested on ios6 in emulator
Reporter: alexander casassovici
Assignee: Shazron Abdullah
/////
//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() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS_w, fail);
}
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) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
};
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 -
{"status":1,"message":"wifi","keepCallback":false}
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":{"name":"iPhone
Simulator","uuid":"E7446481-3D85-48D5-97F4-E80B6FE034EC","platform":"iPhone
Simulator","version":"6.0","cordova":"2.0.0"},"keepCallback":false}
2012-09-24 20:16:31.833 Diveboard[39848:c07] PluginResult
toSuccessCallbackString:
cordova.callbackSuccess('Device1',{"status":1,"message":{"name":"iPhone
Simulator","uuid":"E7446481-3D85-48D5-97F4-E80B6FE034EC","platform":"iPhone
Simulator","version":"6.0","cordova":"2.0.0"},"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":{"name":"readme.txt","isFile":true,"isDirectory":false,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt"},"keepCallback":false}
2012-09-24 20:16:31.842 Diveboard[39848:c07] PluginResult
toSuccessCallbackString:
cordova.callbackSuccess('File3',{"status":1,"message":{"name":"readme.txt","isFile":true,"isDirectory":false,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt"},"keepCallback":false});
2012-09-24 20:16:31.843 Diveboard[39848:c07] PluginResult:toJSONString -
{"status":1,"message":{"type":"","name":"readme.txt","size":16,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt","lastModifiedDate":1348510579000},"keepCallback":false}
2012-09-24 20:16:31.843 Diveboard[39848:c07] PluginResult
toSuccessCallbackString:
cordova.callbackSuccess('File4',{"status":1,"message":{"type":"","name":"readme.txt","size":16,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt","lastModifiedDate":1348510579000},"keepCallback":false});
2012-09-24 20:16:31.844 Diveboard[39848:c07] PluginResult:toJSONString -
{"status":1,"message":16,"keepCallback":false}
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":{"name":"readme.txt","isFile":true,"isDirectory":false,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt"},"keepCallback":false}
2012-09-24 20:16:31.847 Diveboard[39848:c07] PluginResult
toSuccessCallbackString:
cordova.callbackSuccess('File7',{"status":1,"message":{"name":"readme.txt","isFile":true,"isDirectory":false,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt"},"keepCallback":false});
2012-09-24 20:16:31.848 Diveboard[39848:c07] PluginResult:toJSONString -
{"status":1,"message":{"type":"","name":"readme.txt","size":16,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt","lastModifiedDate":1348510591000},"keepCallback":false}
2012-09-24 20:16:31.848 Diveboard[39848:c07] PluginResult
toSuccessCallbackString:
cordova.callbackSuccess('File8',{"status":1,"message":{"type":"","name":"readme.txt","size":16,"fullPath":"/Users/alex/Library/Application
Support/iPhone
Simulator/6.0/Applications/980AABAA-FBAD-449A-9D9D-B32EB668D59E/Documents/readme.txt","lastModifiedDate":1348510591000},"keepCallback":false});
--
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