問題描述
我很難弄清楚如何在原子電子中處理文件上傳.我會發布代碼,但我什至不知道從哪里開始.
I'm having a hard time figuring out how to approach file uploads in atom electron. I would post code but I don't even know where to begin with this one.
在標準 Web 應用程序中,我會通過標準回發或使用 ajax 請求從客戶端發布到服務器.我有一些非常酷的解決方案.但是在電子的情況下,我不確定在哪里或如何發布"電子.文件回來.我想我只想從 node.js 訪問我的 <input type='file'/>
的內容.我該怎么做?
In a standard web app I would post from the client to the server, either via a standard postback or using an ajax request. I have some pretty cool solutions for that. But in the case of electron, I'm not sure where or how to "post" the file back. I guess I just want to access the contents of my <input type='file' />
from node.js. How do I do this?
我可以發布到瀏覽器進程,但我不知道地址"是什么.將是.或者我需要創建一個單獨的頁面"嗎?在我的應用程序中只是為了接受表單帖子?我在網絡開發方面的背景可能讓我看不到一些明顯的答案,有人可以幫忙嗎?
I could post to the browser process, but I don't know what the "address" would be. Or do I need to create a separate "page" in my app just to accept form posts? My background in web-dev is probably blinding me to some obvious answer, can someone help?
只是為了添加更多上下文,我有一個 .csv
文件,我想允許用戶上傳該文件.然后我將使用 node-csv 處理這個并將每個返回的行插入到應用程序的 nedb 數據存儲中.
Just to add a little more context, I have a .csv
file which I'd like to allow the user to upload. I will then process this using node-csv and insert each returned row into the app's nedb datastore.
推薦答案
如果您要在用戶的機器上處理文件,則無需將文件上傳到任何地方,它已經在您需要的地方.您需要做的就是彈出一個對話框,允許用戶瀏覽他們的文件系統并選擇他們希望您的應用程序處理的文件.您可以創建一個按鈕并調用 dialog.showOpenDialog 當用戶按下它時,它會給你一個文件名,然后你可以使用 Node 的 fs.readFile 從磁盤讀取它,然后您可以繼續以任何您想要的方式處理內容.
If you're going to process the file on the user's machine then there is no need to upload the file anywhere, it's already exactly where you need it. All you need to do is popup a dialog to allow the user to browse their file system and select the file they want your app to process. You can create a button and call dialog.showOpenDialog when the user presses it, that will get you a filename and you can then use Node's fs.readFile to read it from disk, then you can go ahead and process the contents in whichever way you want.
這篇關于如何處理電子中的本地文件上傳?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!