如何使用nodejs从%temp%保存和读取文件



这是创建blob文件并将其保存在文件夹中的代码,我想将screen.webm保存到windows临时文件夹中,稍后在上从同一文件夹读取文件

async function handleStop(e) {
const blob = new Blob(recordedChunks, {
type: 'video/webm'
});
const buffer = Buffer.from(await blob.arrayBuffer());
const { filePath } = await dialog.showSaveDialog({
buttonLabel: 'Save video',
defaultPath: `vid-${Date.now()}.webm`
});
fs.writeFile('screen.webm', buffer, function(err){
if(err) throw err;
console.log(err)
})
if (filePath) {
writeFile(filePath, buffer, () => console.log('video saved successfully!'));
}
while(recordedChunks.length>0){
recordedChunks.pop()
}
}

这个功能被破坏了,因为它会将文件保存在js文件所在的同一文件夹中。作为备份,我还添加了一个用户提示,以便用户可以将文件保存到所需的文件夹中。我是usnig electronic JS来建立一个屏幕记录器。

os.tmpdir()以字符串的形式返回临时文件的操作系统默认目录

const os = require('os');
os.tmpdir();

最新更新