1

I am working on Phonegap 1.5.0, Our project needs to copy picture taken from camera using Android device and move it to another folder. All the images are stored in DCIM/100media/camera. How to move those images to another folder? I am using HTC Wildfire S.

I have referred this link,

Thanks in advance.

Kasturi Unde
  • 11
  • 1
  • 2

3 Answers3

4

Here is the solution which worked for me (expanded from this answer by user899641). The image captured will be renamed and moved to a custom folder (in this case, to the folder TestFolder in SD Card)

function capture() {

    // Retrieve image file location from specified source
    navigator.camera.getPicture(getImageURI, function(message) {
        alert('Image Capture Failed');
    }, {
        quality : 40,
        destinationType : Camera.DestinationType.FILE_URI
    });

}

function getImageURI(imageURI) {

    var gotFileEntry = function(fileEntry) {
        alert("got image file entry: " + fileEntry.fullPath);
        var gotFileSystem = function(fileSystem) {

            fileSystem.root.getDirectory("TestFolder", {
                create : true
            }, function(dataDir) {

                // copy the file
                fileEntry.moveTo(dataDir, "1.jpg", null, fsFail);

            }, dirFail);

        };
        // get file system to copy or move image file to
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem,
                fsFail);
    };
    // resolve file system for image
    window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);

    // file system fail
    var fsFail = function(error) {
        alert("failed with error code: " + error.code);

    };

    var dirFail = function(error) {
        alert("Directory error code: " + error.code);

    };
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
nbk
  • 1,992
  • 2
  • 19
  • 34
2

If you are using the FILE_URI approach when taking a picture you can pass that result to window.resolveLocalFileSystemURI to get a FileEntry object. Then you can call the copyTo method on the FileEntry.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
1

then see this link too ;) http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#File
after u capture the photo, u'll be returned the path of the pic, u can use it to save it to another location using the file api. just read and write

ghostCoder
  • 1
  • 9
  • 49
  • 72