简体   繁体   中英

PhoneGap copy files between different folders

I am trying to copy one jpg file from one folder into another in PhoneGap. The method I used is fs.download. However I got the error that the source url is unsupported. Here are the source and destination files.

source = "/var/mobile/Applications/9483756B-8D2A-42C5-8CF7-8D76AAA8FF2C/Shift.app/iqedata/5977e2e9239649d5a7e3b8a54719679f/06e2b8896e51472789fcc27575631f94.jpg";
target = "/var/mobile/Applications/9483756B-8D2A-42C5-8CF7-8D76AAA8FF2C/Documents/memoir/5977e2e9239649d5a7e3b8a54719679f.jpg";

Can anybody help me to implement the copyto method which I think should be the correct one to use to solve this problem? I only got the full path of both source and destination.

Thanks.

您要使用FileEntry对象的copyTo方法: http : //docs.phonegap.com/en/2.6.0/cordova_file_file.md.html#FileEntry

Using copyTo method wasn't always working for me, the moveTo method worked though. The below code, copies a file from the www folder to the /Library/LocalDatabase folder:

function copyToLocation(dbName){
   console.log("Copying :"+dbName);
   window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+ "www/"+dbName,function (fileEntry)
      {
           window.resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory + "Library/LocalDatabase/",function (directory)

              { 
                 fileEntry.moveTo(directory, 'new_dbname.db',function(){
                    console.log('DB Loaded!');

                    },
                  function()
                  {
                      console.log('Unable to load DB');
                  });
              //},null);
         },null);
    }, null);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM