2012-06-08 9 views
13

Ich brauche Foto in diesen Pfad kopieren. aber wie bekommt man es?
PhoneGap iOS, wie bekomme ich App "Dokumente" Ordner vollständigen Pfad?

„iPhone Simulator/5.1/Anwendungen/996C42CE-B8BF-4F1A-B16C-DBF194BD5A71/Documents /“

http://docs.phonegap.com/en/1.8.0/cordova_file_file.md.html#FileTransfer
Ich möchte ein Bild in meine app Ordner Dokumente zum Download bereit. Aber ich weiß nicht, die FullPath jener Dokumente

+0

ist '996C42CE-B8BF-4F1A-B16C-DBF194BD5A71' Ihre Anwendungs-ID oder eine andere Anwendungs-ID? – dhaval

+0

Ja, es ist die Anwendungs-ID im Gerät. – meadlai

Antwort

19

diesen Code Versuchen.

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

Die gist zeigt die Implementierung, die für iOS und Android funktioniert

+1

Es funktioniert perfekt, danke! – meadlai

+0

das ist perfekt.Vielen Dank @dhaval – sampathpremarathna

+4

"/" ist irreführend, ist nicht Root-Verzeichnis, und tatsächlich ist das Home-Verzeichnis der Anwendung (nur auf dem iPad verifiziert). –

Verwandte Themen