Can't download xml file from local filesystem

Viewed 100

I'm developing an electron app and I have an anchor that should download an xml file that's in the temp folder in the user computer. When I click on it the downloading pop-up shows up and I can select where to save the file but when I press save the file doesn't save in the specified folder. On the network tab in dev tools nothing shows up.

This is my code

<a
  :href="filePath"
  class="custom-button-primary big px-3 py-2"
  download="saft.xml"
  style="text-decoration: none;"
  >Download file</a>
1 Answers

I've found the solution. Files on the local system can't seem to be accessed through an anchor, at least in Electron. So for saving you need to implement the saving mechanism with the fs module

  import { dialog } from 'electron';
  import { copyFile } from "fs/promises";
  const downloadFile = (filePath) => {
  dialog
    .showSaveDialog({
      title: "Your title",
      defaultPath: "Default path / Filename",
      properties: ["showOverwriteConfirmation"],
    })
    .then(async (result) => {
      await copyFile(filePath, result.filePath);
    })
    .catch((err) => {
      alert(err);
    });
  }
Related