【问题标题】:how can i save images in local path where i want when i save the images from website using by javascript?当我使用 javascript 从网站保存图像时,如何将图像保存在我想要的本地路径中?
【发布时间】:2019-07-11 09:26:54
【问题描述】:

我是俊昊 我想知道当我使用 js 从网站保存图像时如何更改路径 请给我建议来解决这个问题。

这是我的代码

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

};

我想在我的本地保存到 C:\django\blog\static\img\before_detection 的路径

【问题讨论】:

标签: javascript html image path


【解决方案1】:

注意,canvas.toDataURL() 不希望将本地文件系统路径作为参数传递。

我想将路径保存到 C:\django\blog\static\img\before_detection 在我的本地

在 Chromium/Chrome 导航到chrome://settings,选择Advanced,滚动到Downloads,选择Ask where to save each file before downloading,这将提示用户接受文件并为用户提供一种选择文件所在目录的方法如果单击Save,则保存在操作系统的文件管理器应用程序窗口中。

【讨论】:

  • @원준호 或者,您可以创建一个 Chrome 打包应用程序,请参阅JavaScript/Ajax Write to File
  • 是的,我明白。我重置了我的设置。但这不是我想要的确切结果。但现在它对我有帮助,谢谢!
  • @원준호 您也可以将默认下载目录设置为路径“C:\django\blog\static\img\before_detection”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-08
  • 2017-05-02
  • 1970-01-01
  • 1970-01-01
  • 2013-06-15
  • 1970-01-01
相关资源
最近更新 更多