[英]How do I handle local file uploads in electron?
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.
我会发布代码,但我甚至不知道从哪里开始。
In a standard web app I would post from the client to the server, either via a standard postback or using an ajax request. 在标准的Web应用程序中,我会通过标准回发或使用ajax请求从客户端发布到服务器。 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. 我想我只想从node.js访问我的
<input type='file' />
的内容。 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?
我在web-dev中的背景可能让我觉得有些明显的答案,有人可以帮忙吗?
Just to add a little more context, I have a .csv
file which I'd like to allow the user to upload. 只是为了添加更多的上下文,我有一个
.csv
文件,我想让用户上传。 I will then process this using node-csv and insert each returned row into the app's nedb datastore. 然后我将使用node-csv处理它,并将每个返回的行插入应用程序的nedb数据存储区。
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.
您可以创建一个按钮,并在用户按下它时调用dialog.showOpenDialog ,它将为您提供文件名,然后您可以使用Node的fs.readFile从磁盘读取它,然后您可以继续以任何方式处理内容想。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.