无法从本地文件系统下载 xml 文件
Can't download xml file from local filesystem
我正在开发一个 Electron 应用程序,我有一个锚点可以下载用户计算机临时文件夹中的 xml 文件。当我点击它时,会出现下载弹出窗口,我可以 select 将文件保存到哪里,但是当我按下保存时,文件不会保存在指定的文件夹中。在开发工具的网络选项卡上没有任何显示。
这是我的代码
<a
:href="filePath"
class="custom-button-primary big px-3 py-2"
download="saft.xml"
style="text-decoration: none;"
>Download file</a>
我找到了解决办法。本地系统上的文件似乎无法通过锚访问,至少在 Electron 中是这样。所以为了保存你需要用fs
模块
实现保存机制
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);
});
}
我正在开发一个 Electron 应用程序,我有一个锚点可以下载用户计算机临时文件夹中的 xml 文件。当我点击它时,会出现下载弹出窗口,我可以 select 将文件保存到哪里,但是当我按下保存时,文件不会保存在指定的文件夹中。在开发工具的网络选项卡上没有任何显示。
这是我的代码
<a
:href="filePath"
class="custom-button-primary big px-3 py-2"
download="saft.xml"
style="text-decoration: none;"
>Download file</a>
我找到了解决办法。本地系统上的文件似乎无法通过锚访问,至少在 Electron 中是这样。所以为了保存你需要用fs
模块
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);
});
}