【发布时间】:2023-04-10 03:24:01
【问题描述】:
我创建了一个按钮,用于下载和保存从 api 端点返回的文件。
在普通浏览器中,点击按钮后,会出现一个保存文件对话框,标题为Save As,Save as type由文件扩展名显示。但在electron 中,标题似乎是一个文件网址(在我的情况下,它显示blob://https:... 因为我的是用URL.createObjectURl 创建的)。
那么我需要设置为a标签以使对话框标题为Save As并更正文件的保存类型(不使用电子本机对话框)的任何选项吗?
...
<a hidden href='/' ref={downloadRef}>download</a>
<button onClick={handleSaveFile}>download</button>
...
const handleSaveFiles = (file: Blob, fileName: string): void => {
const fileDownloadUrl = window.URL.createObjectURL(file);
if (downloadRef.current) {
downloadRef.current.href = fileDownloadUrl;
downloadRef.current.download = fileName;
downloadRef.current.click();
}
};
【问题讨论】:
标签: javascript html reactjs electron