0

I have created an application which targets IPad using phonegap. I have created a text file dynamically using phonegap's API. The file location shows /var/mobile/Applications/C9D4....../Documents/DataFiles. How do I access the file?

Please help. Thanks in advance

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • check this other question http://stackoverflow.com/questions/10945375/phonegap-ios-how-to-get-app-documents-folder-full-path – tkanzakic Feb 19 '13 at 07:25
  • Thanks mate!!.. That helped me accessing the file in iMAC . but still have the issue to locate it in iPad. – Srikanth Atmakuri Feb 19 '13 at 10:20
  • you should not try to access the file by its full path because it will be different, instead you must get a reference to the `Documents` folder and then append the name of the file, for example using `[pathToDocumentsFolder stringByAppendingPathComponent:filename]` – tkanzakic Feb 19 '13 at 10:23

1 Answers1

0

try this

function getfile(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail);

function onFail(message) {
      alert('Failed because: ' + message);
    }

    function gotFS(fileSystem) {
        fileSystem.root.getFile("/var/mobile/Applications/C9D4....../Documents/DataFiles", {create: true}, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {
        fileEntry.file(gotFile, fail);
    }

    function gotFile(file){
        readDataUrl(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 fail(evt) {
        console.log(evt.target.error.code);
    }

}

Malek Hijazi
  • 4,112
  • 1
  • 26
  • 31