Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I get a File object from PhoneGap camera.getPicture?

This is probably simple and covered by some combination of functions in PhoneGap's "Camera" plugin, "File" plugin, or "File-Transfer" plugin. I understand the user can select a file with:

navigator.camera.getPicture(function (fileURI) {

    // *** need help here ***

}, function ()
    // handle errors
}, {
    destinationType: window.Camera.DestinationType.FILE_URI,
    sourceType: window.Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: window.Camera.MediaType.ALLMEDIA
});

I can also change to destinationType: window.Camera.DestinationType.DATA_URL if that makes a difference.

My goal in the success handler is to get a File object (https://developer.mozilla.org/en-US/docs/Web/API/File).

like image 712
maxmoore14 Avatar asked Mar 03 '14 17:03

maxmoore14


1 Answers

Something like this should do it.

navigator.camera.getPicture(function (fileURI) {

    window.resolveLocalFileSystemURL(fileURI, 
        function(fileEntry){
            alert("got image file entry: " + fileEntry.fullPath);
            // fileEntry.file() should return a raw HTML File Object
        },
        function(){//error}
    );

}, function (){
// handle errors
}, {
    destinationType: window.Camera.DestinationType.FILE_URI,
    sourceType: window.Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: window.Camera.MediaType.ALLMEDIA
});
like image 87
BlinkyBill Avatar answered Nov 15 '22 15:11

BlinkyBill