简体   繁体   English

是否可以使用javascript在特定目录中保存诸如.swf,.mp3,.txt等文件,而无需“另存为”提示?

[英]Is it possible to save a file such as .swf, .mp3, .txt, etc. without the “save as” prompt using javascript in a specific directory?

I am developing a node-webkit application. 我正在开发一个节点Webkit应用程序。 I would like to download a .swf file when I clicked a button and automatically save it to a specific directory. 单击一个按钮时,我想下载一个.swf文件,并将其自动保存到特定目录。 Right now, I can download it but a "save as" dialog is prompting. 现在,我可以下载它,但是提示“另存为”对话框。 Is it possible to disable it and just automatically save it? 是否可以禁用它并自动保存它? Is this possible with javascript? 使用JavaScript可以吗?

否。否则,恶意网站将能够覆盖您计算机上的重要文件

Node Webkit Apps are not Website, therefore yes, you can do so by using a node module. 节点Webkit应用程序不是网站,因此可以,您可以使用节点模块来实现。 For example, using fs (File system) : 例如,使用fs (文件系统):

var fs = require("fs");
fs.writeFile("myfile.txt", "Yes! with nwjs i can do stuff that i'm not allowed to do in browser!", function(err) {
  if(err)console.log(err)
  else console.log("file saved");
});

Maybe you can read the content of your downloaded file and pipe it to where you want : 也许您可以阅读下载文件的内容并将其通过管道传输到所需位置:

fs.createReadStream(source_file_path).pipe(fs.createWriteStream(dest_file_path))

You are not restricted as in the browser. 您不受浏览器的限制。

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

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