0

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

Thush-Fdo
  • 506
  • 1
  • 9
  • 28
anvesh
  • 71
  • 1
  • 1
  • 9

1 Answers1

0

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);

    }
Ash
  • 2,575
  • 2
  • 19
  • 27