我有这个代码在我的后台.js文件的一个Electron 应用程序.
ipcMain.on('init', (event, ...args) => {
fileSelector = dialog.showOpenDialog({
title: 'Select template',
buttonLabel: 'Upload file',
filters: [
{
name: 'MS Word document', extensions: ['docx']
}
]
}).then( (filePath) => {
//fs.readFile(filePath.filePaths[0], (err, data) => {
event.sender.send('documentPath', filePath.filePaths[0])
//})
}).catch( (error) => console.warn(error) )
})
基本上,我打开了一个本地文件 Select 器,我将在应用程序的VUE前端发送路径
ipcRenderer.send('init')
ipcRenderer.receive('documentPath', (filePath) => {
//this.store.docTemplate = new Blob(data, { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }).arrayBuffer()
fs.readFile(filePath, (error, data) => {
this.store.docTemplate = data
})
console.log(this.store.docTemplate)
})
我在给装在vuejs挂钩上的ipcRenderer
上的听众打电话.我需要做的是从收到的文件路径中读取文件并获得BLOB,如果使用<input type="file">
获得所需文件,则会正常发生BLOB.我需要将斑点传递给this library,那么有什么方法可以实现这一点吗?我try 启用 node 集成,但这会给IPC进程带来问题.
谢谢你的帮助.