var {Cc, Ci, Cu} = require("chrome");
function downloadFile(links) {
try {
//new obj_URI object
var obj_URI = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).newURI(links, null, null);
//new file object
var obj_TargetFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.;
//set file with path
obj_TargetFile.initWithPath("c:\\temp\\1.jpg");
//if file doesn't exist, create
if(!obj_TargetFile.exists()) {
obj_TargetFile.create(0x00,0644);
}
obj_TargetFile.reveal();
//new persitence object
var obj_Persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
// with persist flags if desired
const nsIWBP = Ci.nsIWebBrowserPersist;
const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_DONT_CHANGE_FILENAMES |
nsIWBP.PERSIST_FLAGS_CLEANUP_ON_FAILURE;
obj_Persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
//save file to target
obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile,null);
} catch (e) {
console.error(e);
}
};
此工作代码用于在firefox sdk 1.14上静默下载文件 如何将“ 1.jpg ”的名称更改为真正的下载文件名?
nsIWBP.PERSIST_FLAGS_DONT_CHANGE_FILENAMES
没有任何结果。