我正在使用 Electron 和 ReactJS 构建桌面应用程序。
我需要实现从文件系统中选择文件的功能,例如 input="file"在表单中工作。
其实,我只需要获取文件的绝对路径即可。
我怎样才能做到这一点?
我试过:
<input type="file" onChange={function(e) {console.log(e.target.value)} } />
但出于安全原因,它返回 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
}
})
});
关于javascript - 如何使用 React 和 Electron 在 fs 上选择文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38400685/