13

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.

meadlai
  • 895
  • 1
  • 9
  • 22

1 Answers1

19

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

dhaval
  • 7,611
  • 3
  • 29
  • 38
  • 4
    "/" is misleading, is not root dir, and actually is the application's home directory (just verified on iPad). – Ravindranath Akila Apr 04 '14 at 07:18
  • 2
    on iOS, full path is '/' which is really misleading. I can not download to this path. @RavindranathAkila.. have u found any solution yet..? – shashwat Apr 08 '14 at 08:05
  • Of course each app is sandboxed so root means application's home directory. You think you can access to root file system on iOS? – Tien Do Apr 11 '14 at 03:38
  • should be `fileSystem.root.nativeURL`, or you can't create file with `fullPath` – Enix Feb 24 '17 at 04:41