Firefox addon 火狐52“;“新文件”;更改和错误

Firefox addon 火狐52“;“新文件”;更改和错误,firefox-addon,firefox-addon-bootstrap,Firefox Addon,Firefox Addon Bootstrap,我一直在使用新文件(File.path)在Firefox 17.*到51.*的引导特权代码中。 文件是一个nsi文件 从Firefox52开始,它现在给出了一个错误:TypeError:没有足够的参数来归档。 参考: 已更新,以包含更改 在中(有关详细信息,请参见) Firefox 52.*+现在可以使用什么样的正确代码 应要求更新: // note: aFileURL is a local file let aFileURL = 'file:///C:/Users/***/icon.png';

我一直在使用
新文件(File.path)在Firefox 17.*到51.*的引导特权代码中。
文件
是一个
nsi文件

从Firefox52开始,它现在给出了一个错误:
TypeError:没有足够的参数来归档。

参考:

已更新,以包含更改 在中(有关详细信息,请参见)

Firefox 52.*+现在可以使用什么样的正确代码

应要求更新:

// 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.

感谢Makyen

参考:

MDN声明:
var file=file.createFromFileName(“path/to/some/file”)

以下代码无效:(我的误解)

以下代码起作用:

Components.utils.importGlobalProperties(['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 = File.createFromFileName(file.path);
以下代码也起作用:

Components.utils.importGlobalProperties(['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 = File.createFromNsIFile(file);

其他参考信息:

使用
file=新文件([],file.path)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
但是,使用
file=file.createFromFileName(file.path)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
使用
file=file.createFromNsIFile(文件)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
文件
从第一个代码传递到
FileReader()
会产生错误的结果<代码>“数据:应用程序/八位字节流;base64”,

文件
从第二个和第三个代码传递到
FileReader()
会产生正确的结果。
“数据:图像/png;base64,IVBorW0KggoaaaAnsuheugaabacayaaCqaxheaaqjulleqVR42UWBB3QU17NHV7UZQ60S6Sjgotniargyucqczavkhh0QoSzgXpHwGjHwGjHwGjPjRfHyBt4EeLagawghaBjweyGcmExekCjSiujaxyxDHO8V…”

多亏了Makyen

参考:

MDN声明:
var file=file.createFromFileName(“path/to/some/file”)

以下代码无效:(我的误解)

以下代码起作用:

Components.utils.importGlobalProperties(['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 = File.createFromFileName(file.path);
以下代码也起作用:

Components.utils.importGlobalProperties(['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 = File.createFromNsIFile(file);

其他参考信息:

使用
file=新文件([],file.path)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
但是,使用
file=file.createFromFileName(file.path)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
使用
file=file.createFromNsIFile(文件)生成以下内容:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }
File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "C:\Users\...\icon.png", size: 4294, type: "image/png" }
文件
从第一个代码传递到
FileReader()
会产生错误的结果<代码>“数据:应用程序/八位字节流;base64”,

文件
从第二个和第三个代码传递到
FileReader()
会产生正确的结果。
“数据:image/png;base64,ivborw0kggoaaansuheugaaaabacayaacqaxheaaqjulleqvr42uwbb3qu17nhv7uzq60s6sjgotniargyucqczavkhh0qoszgxpjshwgjrjrafwthwkzeybt4eelagawghabjweygcmexekcjsijaxyxdho8v…”请提供更多代码。虽然一个完整的文件可能有点多,但我们至少需要让您显示/确认
文件的定义位置。我们可以猜测,但这只是一个有根据的猜测。我添加了更多的代码。虽然它唯一显示的是
文件
是一个
nsi文件
,这是在原始帖子中提到的。注意:代码从Firefox 17一直运行到Firefox 51,只有Firefox 52中的更改导致了错误。基于此,您似乎应该使用
var file=file.createFromNsIFile(dsFile)
var file=file.createFromFileName(“path/to/some/file”)您还没有说明
file=file.createFromFileName(file.path)的错误
file=file.createFromNsIFile(文件)使用
var foo=File.createFromFileName();console.log(foo)在FF53.0a2中对我来说效果很好。我对MCVE的请求是因为您声明
File.createFromNsIFile()
File.createFromFileName()
都会为您产生错误。它们对我很管用。您没有指定错误,因此我要求MCVE能够重现这些问题。是的,代码“`var foo=new File();”不起作用,导致参数太少的错误。如果要使用
newfile()
构造函数,可以使用:
var foo=newfile([],)。我已经找到了规范并测试了代码。我会写一个答案。请提供更多的代码。虽然一个完整的文件可能有点多,但我们至少需要让您显示/确认
文件的定义位置。我们可以猜测,但这只是一个有根据的猜测。我添加了更多的代码。虽然它唯一显示的是
文件
是一个
nsi文件
,这是在原始帖子中提到的。注意:代码从Firefox 17一直运行到Firefox 51,只有Firefox 52中的更改导致了错误。基于此,您似乎应该使用
var file=file.createFromNsIFile(dsFile)
var file=file.createFromFileName(“path/to/some/file”)您还没有说明
file=file.createFromFileName(file.path)的错误
file=file.createFromNsIFile(文件)使用
var foo=File.createFromFileName();console.log(foo)在FF53.0a2中对我来说效果很好。我对MCVE的请求是因为您声明
File.createFromNsIFile()
File.createFromFileName()
都会为您产生错误。它们对我很管用。您没有指定错误,因此我要求MCVE能够重现这些问题。是的,代码“`var foo=new File();”不起作用,导致参数太少的错误。如果要使用
newfile()
构造函数,可以使用:
var foo=newfile([],)。我已经找到了规范并测试了代码。我会写一个答案。参考资料:显示3个论点。明确说明需要2个或3个参数(这与
文件
实现说明中的说明隐式冲突,说明特权代码可以通过
文件()
构造函数传递
nsfile
对象)。你可能想和我谈谈