Robert
Robert

Reputation: 302

How to resolve error with fileentry.copyTo(), Cordova 1.6.1

I'm trying to execute the copyTo method on a FileEntry and it's failing with an error code of 1. I suspect I'm not giving it what it needs. Here is the input I'm providing to the method, which one of these values is incorrect? Running on android but also getting the error on iOS. I'm attempting to follow the instructions from the API docs, but the expected input is not clear.

var imageUri = 'file:///mnt/sdcard/Android/data/com.test.app/cache/resize.jpg?1337214925787';
var newFileName = 'test.jpg';
var directoryFullPath = 'file:///mnt/sdcard/App/Job';

window.resolveLocalFileSystemURI(
   imageUri,
   function (entry) {
    console.log("Get file entry success, copy file");
    var parentEntry = new DirectoryEntry({ fullPath: directoryFullPath});
    entry.copyTo(
        parentEntry,
        newFileName,
        function (newEntry) {
            console.log("FileEntry copy to done. New Path: " + newEntry.fullPath);
         },
         function (error) {
             console.log("FileEntry copy to fail. Error code: " + error.code);
         }
...

Upvotes: 2

Views: 4742

Answers (1)

Robert
Robert

Reputation: 302

I structured my code like the example in this post and was able to execute successfully. Maybe it was a closure issue I didn't see, not sure, but the sample below works.

FYI, it looks like this throws an error if the file already exists, so I had to modify my code to add a timestamp to the file name to guard against that.

Phonegap - Retrieve photo from Camera Roll via path

Upvotes: 1

Related Questions