user899641
user899641

Reputation: 351

Android - Phonegap - How to get the file name of the picture taken

So when I take pictures they get saved to DCIM/Camera/ directory. I need to retrieve the pictures after taken to send via email.

How can I get the name of the last picture taken? (Or adjust my current code to customize the file name.)

Here's the code for taking the picture:

function capturePhoto(id) { 
navigator.camera.getPicture(onSuccess, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI });    

function onSuccess(imageURI) {  
var image = document.getElementById(id);  

image.style.display = 'block'; 
image.src = imageURI;  

}   

function onFail(message) {  
alert('Failed because: ' + message);  
}  
}

Upvotes: 3

Views: 7736

Answers (1)

user899641
user899641

Reputation: 351

Here's the answer to my question. You have to be running Phonegap 1.0. This will put the picture where ever you want it and name it what ever you want. So then you can reference by filename and do what ever you want with it.

var gotFileEntry = function(fileEntry) { 
            console.log("got image file entry: " + fileEntry.fullPath); 
            var gotFileSystem = function(fileSystem){ 
                // copy the file 
                fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null); 
           }; 
            // 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 
    function fsFail(error) { 
        console.log("failed with error code: " + error.code); 
    }; 

Upvotes: 8

Related Questions