1

i am junho I'm wondering how can i change the path when i save the images from website using js please give me advice to solve this problem.

here is my code

(function(){
  var video = document.getElementById('video'),
      photo = document.getElementById('photo'),
      context = canvas.getContext('2d'),
      vendorUrl = window.URL || window.webkitURL;


  navigator.getMedia = navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia;

  navigator.getMedia({
      video:true,
      audio:false
  }, function(stream){
      video.srcObject=stream;
      video.play();
  }, function(error){

  });



  document.getElementById('capture').addEventListener('click', function(){
      context.drawImage(video, 0, 0, 400, 300);
      photo.setAttribute('src', canvas.toDataURL('C:/django/blog/static/img/png'))

      console.log(canvas);
      saveAs(canvas.toDataURL(), 'file-name.png')
  });
})();

function saveAs(uri, filename){
    var link = document.createElement('a');

    if (typeof link.download === 'string'){
        link.href = uri;
        link.download = filename;

        document.body.appendChild(link);

        link.click();

        document.body.removeChild(link);
    } else {
      window.open(uri);
    }

};

i want to save the path to C:\django\blog\static\img\before_detection in my local

원준호
  • 33
  • 6
  • Possible duplicate of [How can I move a file to other directory using JavaScript?](https://stackoverflow.com/questions/17586382/how-can-i-move-a-file-to-other-directory-using-javascript) – Aniket G Feb 18 '19 at 02:53

1 Answers1

2

Note, canvas.toDataURL() does not expect a local filesystem path to be passed as parameter.

i want to save the path to C:\django\blog\static\img\before_detection in my local

At Chromium/Chrome navigate to chrome://settings, select Advanced, scroll to Downloads, select Ask where to save each file before downloading, which will prompt user to accept file and provide a means for user to select which directory the file will be saved in at the OS's file manager application window, if Save is clicked.

guest271314
  • 1
  • 15
  • 104
  • 177
  • @원준호 Alternatively you can create a Chrome packaged app, see [JavaScript/Ajax Write to File](https://stackoverflow.com/questions/42460493/javascript-ajax-write-to-file) – guest271314 Feb 18 '19 at 03:20
  • yes i understand. i reset my settings. but it is not the exact result i want.but for now it is helpful for me thank you! – 원준호 Feb 18 '19 at 03:36
  • @원준호 You can alternatively set the default download directory to the path "C:\django\blog\static\img\before_detection" – guest271314 Feb 18 '19 at 03:42