JavaScript - 将图像从 URL 保存到本地机器特定路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29423809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript - Save image from URL to local machine specific path?
提问by ChiMo
Using jQuery/javascript I am making a personal program for me and my friends to use. I wanted to have a functionality that downloads a file from an external (online) url and then save it to a particular directory relative to my /root folder.
使用 jQuery/javascript 我正在制作一个供我和我的朋友使用的个人程序。我想要一个功能,可以从外部(在线)url 下载文件,然后将其保存到与我的 /root 文件夹相关的特定目录中。
I cannot use this on a server as I just want to run the html file locally - however it may be hosted online in the future.
我不能在服务器上使用它,因为我只想在本地运行 html 文件 - 但它可能在未来在线托管。
I'm not worried about security at this current point in time - so is this possible to do?
在当前时间点,我并不担心安全性 - 那么这可能吗?
回答by tnschmidt
In Javascript you cannot directly save a file to your root folder or choose the location of where the file is saved. However with Javascript you can cause the browser to prompt the user to save the file locally. Take a look at this github project:
在 Javascript 中,您不能直接将文件保存到根文件夹或选择保存文件的位置。但是,使用 Javascript,您可以使浏览器提示用户将文件保存在本地。看看这个github项目: