简体   繁体   English

如何在HTML中单击按钮后在远程计算机上下载文件?

[英]How to download a file on a remote machine on button click in html?

I'm trying to download a file on a remote machine on button click in html. 我正在尝试在HTML中单击按钮时在远程计算机上下载文件。 Like I have link of a file which is " File link: - https://perso.telecom-paristech.fr/eagan/class/igr204/data/Camera.csv ". 就像我有一个文件的链接,即“ 文件链接: -https : //perso.telecom-paristech.fr/eagan/class/igr204/data/Camera.csv ”。 I want to download this file to a remote machine on a button click in html. 我想通过单击html上的按钮将此文件下载到远程计算机。 I don't know how to connect to remote machine for downloading that file. 我不知道如何连接到远程计算机以下载该文件。 So it will be like, when I'm clicking on download button in html file on my machine / local machine , this file should get downloaded to the remote machine or some other machine instead of my local machine. 因此,就像当我单击本地计算机上的html文件中的html文件中的下载按钮时,该文件应下载到远程计算机或其他本地计算机而非本地计算机上。 Will "ip address" will be sufficient to connect to remote machine and store the file in that machine? “ ip地址”是否足以连接到远程计算机并将文件存储在该计算机中?

Can someone please help to do that or tell me other way to get it done? 有人可以帮忙吗,或告诉我其他方法来完成它吗?

Web browsers provide no mechanism for a website to determine where a file will be saved, so even if they had access to the target machine, you couldn't do this with client-side code. Web浏览器没有提供任何机制的一个网站以确定一个文件将被保存,所以即使他们进入到目标机器,你不能与客户端代码做到这一点。

You need to write a web service (you can use whatever programming language you like, my preference these days would be to use JavaScript with the Express module (to provide the web service) and Axios (to do the download) for Node.js). 您需要编写一个Web服务(您可以使用任何喜欢的编程语言,如今,我的首选是将JavaScript与Node.js的Express模块​​(提供Web服务)和Axios(进行下载)结合使用) 。

You need to make an HTTP request to the web service when the button is clicked (this can be as simple as using a <form> with the action URL pointing to the web service so a request is made to it when the submit button is clicked. 单击按钮时,您需要向Web服务发出HTTP请求(这可以像使用<form>那样简单, action URL指向Web服务,因此单击“提交”按钮时便对其进行了请求。 。

Then the web server needs to perform the download. 然后,Web服务器需要执行下载。

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

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