[英]How to Save As using Node-Webkit
Using Node-Webkit, The following page, 使用Node-Webkit,下一页,
https://github.com/rogerwang/node-webkit/wiki/File-dialogs https://github.com/rogerwang/node-webkit/wiki/File-dialogs
Describes that you can use [input type="file" nwsaveas="filename.txt" /] to open a File Save dialog. 描述您可以使用[input type =“ file” nwsaveas =“ filename.txt” /]打开“文件保存”对话框。
However it does not explain how would you write the data to the filesystem. 但是,它没有解释如何将数据写入文件系统。
I expected/imagined something simple like, 我曾期望/想象过一些简单的事情,
var directory = FileOpen();
fs.writeFile(directory+"myfile.png", buffer);
Is there any explanation for this? 有什么解释吗?
You are right, after you trigger the Save As dialog, you will be prompted a dialog, specify the name, and you could receive the file path by doing this. 没错,在触发“另存为”对话框后,将提示您一个对话框,指定名称,这样您可以收到文件路径。
Sample Code (using jQuery): 示例代码(使用jQuery):
$("#save").trigger("click");
$("#save").on("change", function () {
var filePath = $(this).val();
if (filePath !== "") {
var fs = require("fs");
fs.writeFile(filePath, "Hello World", function (err) {
if (err)
alert("Unable to save file");
else
console.log("saved. ");
});
}
else {
// User cancelled
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.