61
rated 0 times
[
62]
[
1]
/ answers: 1 / hits: 24634
/ 10 Years ago, fri, july 18, 2014, 12:00:00
How do you convert a local (filesystem) URI to path?
It can be done with nsIIOService
+ newURI()
+ QueryInterface(Components.interfaces.nsIFileURL)
+ file.path
but that seems like a long way.
Is there a shorter way?
Here is an example code:
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-fileroot.png
More From » firefox-addon