anvesh
anvesh

Reputation: 81

how to open the camera from browser and save the image in local directory for Cordova

I have a code to Open the Camera from browser. How to improve this code so that i can save the file in local directory.

document.getElementById('takephoto').onclick = function(){
    console.log(navigator.camera);
    navigator.camera.getPicture(function(imageUri){
        var lastphoto = document.getElementById("thephoto");
        alert("nicephoto");
        lastphoto.innerHTML = "<img src='" + imageUri + "'style='width:100%;'/>"
    }, null, null);

}

With this code I can access the Camera

Upvotes: 0

Views: 469

Answers (1)

Ash
Ash

Reputation: 2595

Try using this and see if that helps

  document.getElementById('takephoto').onclick = function(){
        console.log(navigator.camera);
        navigator.camera.getPicture(function(imageUri){
            var lastphoto = document.getElementById("thephoto");
            alert("nicephoto");
            lastphoto.innerHTML = "<img src='" + imageUri + "'style='width:100%;'/>";
            var a = document.createElement("a"),
                url = URL.createObjectURL(file);
            a.href = url;
            a.download = filename;
            document.body.appendChild(a);
            a.click();
            setTimeout(function() {
             document.body.removeChild(a);
              window.URL.revokeObjectURL(url);  
            }, 0); 
            download(imageUri, "someFilename.jpg", "image");
        }, null, null);

    }

Upvotes: 0

Related Questions