I have been using new File(file.path);
in bootstrapped privileged code from Firefox 17.* to 51.*.
file
is an nsIFile
.
As of Firefox 52, it now gives an error: TypeError: Not enough arguments to File.
ref: Firefox 52 for developers
The File and Directory Entries API has been updated to include changes in the latest spec (see bug 1284987 for the exact details).
What would be an example of the proper code to use now for Firefox 52.*+?
Update upon request:
// note: aFileURL is a local file
let aFileURL = 'file:///C:/Users/***/icon.png'; // just an example
let file = Services.io.newURI(aFileURL, null, null)
.QueryInterface(Components.interfaces.nsIFileURL).file; // convert URL to nsIFile
file = new File(file.path); // Firefox 52: TypeError: Not enough arguments to File.
Thanks to Makyen
ref: Using the DOM File API in chrome code
MDN stated:
var file = File.createFromFileName("path/to/some/file");
The following code didn't work: (my misunderstanding)
The following code works:
The following code also works:
Additional info for reference:
Using
file = new File([], file.path);
produces the following:However, using
file = File.createFromFileName(file.path);
produces the following:Using
file = File.createFromNsIFile(file);
produces the following:Passing the
file
from the first code toFileReader()
produces the wrong result."data:application/octet-stream;base64,"
Passing the
file
from the 2nd & 3rd code toFileReader()
produces the correct result."data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAQjUlEQVR42uWbB3QU17nHv7uzq60S6sJGotniARGYUCQcZAvkhh0QosZgXPJsHwgJpiTB4Aq4JrafwTHvkZeYBBt4EELAGAwGhABjwEYgcMExEk1CjSIJaXuZyXdHO8v..."