2010-04-29 47 views
0

无视我以前的编辑前的帖子。重新审视我需要做的事情。这是目前我在做什么: 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 

正如你可以看到目录中有硬编码的,我要保存PDF文件打开在活动选项卡相对临时目录,或任何地方,是超出的方式足以让用户不会绊倒并删除它。我将尝试使用File I/O,我的印象是我所寻找的是可脚本化的文件I/O,因此被禁用。

+0

下面是我一直在使用的一些资源,它不会让我发布。 https://developer.mozilla.org/en/Code_snippets/Downloading_Files https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Streams https://developer.mozilla.org/en/NsIIOService http://www.oxymoronical.com/experiments/apidocs/interface/nsIInputStreamPump https://developer.mozilla.org/zh/Code_snippetsMiscellaneous#Saving_the_current_web_page_to_a_local_file – Nathan 2010-04-29 15:21:14

回答

1

我想你想this,但你的问题是非常含糊。

+0

谢谢。我正在尝试,但我想我做错了什么。 – Nathan 2010-05-04 14:04:30