Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap iOS, how to get app "Documents" folder full path?

I need copy photo into this path. but how to get it?

“iPhone Simulator/5.1/Applications/996C42CE-B8BF-4F1A-B16C-DBF194BD5A71/Documents/"

http://docs.phonegap.com/en/1.8.0/cordova_file_file.md.html#FileTransfer
I want to download a image into my app documents folder. but I do not know the FullPath of that documents.

like image 315
meadlai Avatar asked Jun 08 '12 08:06

meadlai


1 Answers

Try this code:

document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
        console.log("device is ready");
        window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }

    function fail() {
        console.log("failed to get filesystem");
    }

    function gotFS(fileSystem) {
        console.log("got filesystem");

            // save the file system for later access
        console.log(fileSystem.root.fullPath);
        window.rootFS = fileSystem.root;
    }

    function downloadImage(url, fileName){
        var ft = new FileTransfer();
        ft.download(
            url,
            window.rootFS.fullPath + "/" + fileName,
            function(entry) {
                console.log("download complete: " + entry.fullPath);

            },
            function(error) {
                console.log("download error" + error.code);
            }
        );
    }

The gist shows the implementation which works for both iOS and Android

like image 172
dhaval Avatar answered Oct 18 '22 09:10

dhaval