如何使用 React 和 Electron 在 fs 上 select 归档?
How to select file on fs with react and electron?
我正在使用 Electron 和 ReactJS 构建桌面应用程序。
我需要从文件系统实现 select 文件的功能,例如 input="file" 在表单中工作。
其实我只需要获取文件的绝对路径即可。
我怎样才能做到这一点?
我试过:
<input type="file" onChange={function(e) {console.log(e.target.value)} } />
但出于安全原因,它 returns fakepath。
我认为 Electron 中的对话框可能对此有用,但是如何传播文件路径以响应应用程序呢?
const {dialog} = require('electron').remote;
...
document.querySelector('#fileSelect').addEventListener('click', function (event) {
dialog.showOpenDialog({
properties: ['openFile', 'multiSelections']
}, function (files) {
if (files !== undefined) {
// handle files
}
})
});
我正在使用 Electron 和 ReactJS 构建桌面应用程序。
我需要从文件系统实现 select 文件的功能,例如 input="file" 在表单中工作。
其实我只需要获取文件的绝对路径即可。
我怎样才能做到这一点?
我试过:
<input type="file" onChange={function(e) {console.log(e.target.value)} } />
但出于安全原因,它 returns fakepath。
我认为 Electron 中的对话框可能对此有用,但是如何传播文件路径以响应应用程序呢?
const {dialog} = require('electron').remote;
...
document.querySelector('#fileSelect').addEventListener('click', function (event) {
dialog.showOpenDialog({
properties: ['openFile', 'multiSelections']
}, function (files) {
if (files !== undefined) {
// handle files
}
})
});