2016-07-15 55 views
3

我正在用Electron和ReactJS構建桌面應用程序。
我需要實現功能來從文件系統中選擇文件,如input =「file」在窗體中工作。其實,我所需要的只是獲得文件的絕對路徑。
我該如何做到這一點?如何在fs上選擇反應和電子文件?

我想:

<input type="file" onChange={function(e) {console.log(e.target.value)} } /> 

但fakepath由於安全原因返回。
我認爲Electron中的Dialogs可能對此有用,但是如何傳播文件路徑以響應應用程序呢?

+1

可以[this](https://discuss.atom.io/t/open-external-file-with-electron/18569/7)幫助你嗎? – Li357

+0

我需要以用戶友好的方式獲取文件的路徑。 – user3324314

+0

定義'用戶友好' – Li357

回答

1
const {remote} = require('electron'); 
    const {app, dialog} = require('electron').remote; 

...

document.querySelector('#fileSelect').addEventListener('click', function (event) { 
    dialog.showOpenDialog({ 
     properties: ['openFile', 'multiSelections'] 
    }, function (files) { 
     if (files !== undefined) { 
      // handle files 
     }    
    }) 
}); 
0

你不能做到這一點。這是一個安全定義,目前不能轉置。

相關問題