【发布时间】:2014-07-18 04:42:19
【问题描述】:
如何将本地(文件系统)URI 转换为路径?
可以使用nsIIOService + newURI() + QueryInterface(Components.interfaces.nsIFileURL) + file.path 来完成,但这似乎还有很长的路要走。
有没有更短的方法?
这是一个示例代码:
var aFileURL = 'file:///C:/path-to-local-file/root.png';
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var url = ios.newURI(aFileURL, null, null); // url is a nsIURI
// file is a nsIFile
var file = url.QueryInterface(Components.interfaces.nsIFileURL).file;
console.log(file.path); // "C:\path-to-local-file\root.png"
【问题讨论】:
-
您能否举例说明您开始使用的内容和想要结束的内容。可选:还有一个 sn-p 以显示您当前的操作方式。
-
啊,很酷的问题,你想把它变成一条可以提供
DOMFileAPI 的路径,对吧? -
@Noitidart 根据我的其他 2 个问题,我想用它来上传文件
标签: javascript firefox-addon firefox-addon-restartless