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

143
Visualizações
How to make the FileSystemAPI-written file appear on the bottom as if it were downloaded?

I used to handle file downloading by creating an anchor element and clicking on it:

exports.saveBlobAsFileImpl = blob => filename => () => {
    var a = document.createElement("a");
    var url = URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    setTimeout(function(){
        document.body.removeChild(a);
        window.URL.revokeObjectURL(url);
    }, 100);
    return true;
};

(don't mind that the function is curried, it's because the function is exported to PureScript). It works nicely but the downside of it is that it is always downloaded to the default location, and the user cannot overwrite the filename given. So I turned to the new FileSystem API:

exports.saveBlobAsFileImpl = blob => filename => () => {
  window.showSaveFilePicker({ suggestedName: filename })
    .then(fileHandle => fileHandle.createWritable())
    .then(stream => {
      stream.write(blob);
      stream.close();
    })
    .catch(err => console.log("SaveFile aborted"));
    return true;
};

It also works fine (the user chooses the directory and can change the default hardcoded filename). However, now he is unable to open the file right away, as it isn't shown the way downloaded files are (on the bottom of the screen in Chrome). He has to open the file explorer on the folder he downloaded it to, and open from there.

Here is my question: can I have the advantages of both worlds, i.e. ability of the user to select a folder to which he wants to download the blob and overwrite the filename if necessary, and show the downloaded file on the bottom of the screen so the user can open it right away?

about 4 years ago · Juan Pablo Isaza
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