简体   繁体   English

上传文件到 Node 服务器

[英]Upload a file into Node server

I am using angular 4 in client side and written nodejs & express services with MongoDB to upload a file into the server .Here in my angular side i am using the code <input type="file" id="myfile" /> and sending the path of the file to the server for uploading that file into server i am using document.getElementById("myid") .value;我在客户端使用 angular 4 并使用 MongoDB 编写 nodejs 和 express 服务将文件上传到服务器。在我的 angular 端,我使用代码<input type="file" id="myfile" />并发送用于将该文件上传到服务器的文件到服务器的路径我正在使用document.getElementById("myid") .value; to get the path of the file but it gives me the path as C:/fakepath/myfilename.txt but for uploading the file i need the correct path not the fakepath.获取文件的路径,但它给了我C:/fakepath/myfilename.txt的路径,但为了上传文件,我需要正确的路径而不是C:/fakepath/myfilename.txt路径。 I have searched in google they are saying the true path is disabled by the modern browser for some security reason, Is there any workaround for this?我在谷歌搜索过他们说现代浏览器出于某种安全原因禁用了真实路径,有什么解决方法吗?

The point of a file input is to send the file to the server.文件输入的目的是将文件发送到服务器。 That is your "workaround".那是您的“解决方法”。

The file path is useless to you: It is the path on the visitors computer which your server can't access.文件路径对您没有用:它是您的服务器无法访问的访问者计算机上的路径。

Just upload the file normally.只需正常上传文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM