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

230
Visualizações
Get the file path where user downloaded a file

I currently have a function that prompts the user to download a JSON file:

    function downloadObjectAsJson (exportObj, exportName) {
      const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(exportObj))
      let downloadAnchorNode = document.createElement('a')
      downloadAnchorNode.setAttribute('href', dataStr)
      downloadAnchorNode.setAttribute('download', exportName + '.json')
      document.body.appendChild(downloadAnchorNode) // required for firefox
      downloadAnchorNode.click()
      downloadAnchorNode.remove()
    }

Is there a way to get the path the user selected to download this file to? Just need it to be displayed on the UI.

There are some API available that somehow allows access to the client file system like this, which lists down all the files in the selected directory:

async function listFilesInDirectory () {
      const dirHandle = await window.showDirectoryPicker()
      const promises = []
      for await (const entry of dirHandle.values()) {
        if (entry.kind !== 'file') {
          break
        }
        promises.push(entry.getFile().then((file) => `${file.name} (${file.size})`))
      }
      console.log(await Promise.all(promises))
   }

So I thought there might be some way to also get the path selected by the user when saving files.

Any other suggestions/means are welcome.

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