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

cannot read file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.1.0
    • cordova-ios
    • 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()

      { 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});

      Attachments

        Activity

          People

            mmocny Michal Mocny
            alexksso alexander casassovici
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: