Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

493
Visualizações
Download html2canvas image to specific file path
export default class Thumbnail {
getThumbnail(canvas) {
    html2canvas(canvas)
    .then((canvas) => {
        this.saveAs(canvas, 'thumbnail.png');
    }).catch(function(err) {
        console.log(err);
    })
}

saveAs(canvas, filename) {
    let link = document.createElement('a');
    if (typeof link.download === 'string') {
        link.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
        link.download = filename;

        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    } else {
        window.open(canvas);
    } 
  }
}

I have created a module Thumbnail taking canvas tag as its parameter to take a screen capture of the designated area when called from the html script tag (so whenever I refresh the local page, it calls the module)

As far as I know, the html2canvas saves the image to the download folder as its default. If I would like to save an image to a specific file path what should I do?

For example, if I would like to save the image into a folder with a file path of ./Desktop/Project/Assets/Thumbnail, is there any way to add such command inside the code?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No web browser will permit this.

You as the page author have zero control over where the file is saved. This is as much for security and privacy as it is about user preferences.

This applies to all downloads, not just files created by the html2canvas package.


If you're building a tool that only you will use (and it sounds like you are), you may be able to accomplish the same result by writing a non-web shell script that monitors your Downloads directory and moves these files to the special location when they appear.

For that to work, you'd want to give all the screenshots names that follow a pattern you can easily recognize with your shell script.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda