Changing save directory
Posted
by Nathan
on Stack Overflow
See other posts from Stack Overflow
or by Nathan
Published on 2010-04-29T15:20:55Z
Indexed on
2010/05/04
12:08 UTC
Read the original article
Hit count: 339
Disregard my previous pre-edit post. Rethought what I needed to do. This is what I'm currently doing: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIScriptableIO
downloadFile: function(httpLoc) {
try {
//new obj_URI object
var obj_URI = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).
newURI(httpLoc, null, null);
//new file object
//set file with path
obj_TargetFile.initWithPath("C:\\javascript\\cache\\test.pdf");
//if file doesn't exist, create
if(!obj_TargetFile.exists()) {
obj_TargetFile.create(0x00,0644);
}
//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;
obj_Persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
//save file to target
obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile);
return true;
} catch (e) {
alert(e);
}
},//end downloadFile
As you can see the directory is hardcoded in there, I want to save the pdf file open in the active tab to a relative temporary directory, or anywhere that's out of the way enough that the user won't stumble along and delete it. I'm going to try that using File I/O, I was under the impression that what I was looking for was in scriptable file I/O and thus disabled.
© Stack Overflow or respective owner