我在配合反应。我有个文件要下载。及其下载到浏览器默认保存位置(下载文件夹)
FileSaver.saveAs(res.data, fileTitle + "." + fileExtension);我发现用FileSaver.saveAs方法是不可能改变的。所以我想知道是否有另一种方法可以将文件保存到本地路径。
发布于 2022-09-06 07:36:13
不能使用FileSaver库将文件保存到特定路径。
但是有一个新的文件系统API可以用来实现这一点。googlechromelabs是一个简单的文本编辑器 (演示),旨在试验和演示新的文件系统访问API( File )。
要保存文件,请调用showSaveFilePicker(),它以“保存”模式显示文件选择器,允许用户选择要用于保存的新文件。
async function getNewFileHandle() {
const options = {
types: [
{
description: 'Text Files',
accept: {
'text/plain': ['.txt'],
},
},
],
};
const handle = await window.showSaveFilePicker(options);
return handle;
}// fileHandle is an instance of FileSystemFileHandle..
async function writeFile(fileHandle, contents) {
// Create a FileSystemWritableFileStream to write to.
const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write(contents);
// Close the file and write the contents to disk.
await writable.close();
}https://stackoverflow.com/questions/73617181
复制相似问题