我正在开发一个电子应用程序,我有一个锚,它应该下载一个xml文件,它位于用户计算机的temp文件夹中。当我点击它时,下载弹出窗口出现,我可以选择保存文件的位置,但当我按下保存时,文件不会保存在指定的文件夹中。在dev tools中的network选项卡上,没有显示任何内容。
这是我的代码
<a
:href="filePath"
class="custom-button-primary big px-3 py-2"
download="saft.xml"
style="text-decoration: none;"
>Download file</a>发布于 2021-11-11 10:25:20
我已经找到解决方案了。本地系统上的文件似乎不能通过锚点访问,至少在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);
});
}https://stackoverflow.com/questions/69915493
复制相似问题