Firefox 52“新文件”更改和错误 [英] Firefox 52 "New File" changes and error

查看:297
本文介绍了Firefox 52“新文件”更改和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Firefox $ 17的引导特权代码中的 new File(file.path); 。*。

file 是一个 nsIFile



它现在给出了一个错误: TypeError:文件没有足够的参数



ref: Firefox 52 for developers


文件和目录条目API 已经更新,在最新规范中包含更改
(请参阅 bug 1284987 )。




什么是适用于Firefox 52的正确代码示例。

更新请求:

  //注意:aFileURL是一个本地文件
让aFileURL ='file:/// C:/Users/***/icon.png'; //只是一个例子
let file = Services.io.newURI(aFileURL,null,null)
.QueryInterface(Components.interfaces.nsIFileURL).file; //将URL转换为nsIFile
file = new File(file.path); //火狐52:TypeError:文件没有足够的参数。


解决方案

感谢 Makyen



ref:使用在Chrome代码中使用DOM File API



MDN指出: var file = File.createFromFileName(path / to / some / file );



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

  //使用文本URL 
Components.utils.importGlobalProperties(['File']);
让aFileURL ='file:/// C:/Users/***/icon.png'; //只是一个例子
let file = File.createFromFileName(aFileURL);
//File error:Unrecognized pathnsresult:0x80520001(NS_ERROR_FILE_UNRECOGNIZED_PATH)

下面的代码工作:
$ b $ pre $ Components.utils.importGlobalProperties(['File']);
让aFileURL ='file:/// C:/Users/***/icon.png'; //只是一个例子
let file = Services.io.newURI(aFileURL,null,null)
.QueryInterface(Components.interfaces.nsIFileURL).file; //将URL转换为nsIFile
file = File.createFromFileName(file.path);

以下代码也适用:

  Components.utils.importGlobalProperties([ '文件']); 
让aFileURL ='file:/// C:/Users/***/icon.png'; //只是一个例子
let file = Services.io.newURI(aFileURL,null,null)
.QueryInterface(Components.interfaces.nsIFileURL).file; //将URL转换为nsIFile
file = File.createFromNsIFile(file);






其他信息供参考:



使用 file = new File([],file.path); 产生以下结果:

 文件{name:C:\ Users \ ... \icon.png,lastModified:1487509240391,lastModifiedDate:Date 2017-02-19T13: 00:40.391Z,webkitRelativePath:,mozFullPath:,size:0,type:} 



然而,使用 file = File.createFromFileName(file.path); 会产生以下结果:

<$ p $ webkitRelativePath:,mozFullPath:,size:4294,这个文件名称为键入:image / png}

使用 file = File.createFromNsIFile文件); 产生以下内容:

 文件{name:icon.png,lastModified: 1403974172431,lastModifiedDate:Date 2014-06-28T16:49:32.431Z,webkitRelativePath:,mozFull路径:C:\ Users \ ... \icon.png,size:4294,type:image / png} 


$ b

将第一个代码中的文件传递给 FileReader()错误的结果。 data:application / octet-stream; base64



传递 / code>从2nd&第三个代码到 FileReader()产生正确的结果。
数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAQjUlEQVR42uWbB3QU17nHv7uzq60S6sJGotniARGYUCQcZAvkhh0QosZgXPJsHwgJpiTB4Aq4JrafwTHvkZeYBBt4EELAGAwGhABjwEYgcMExEk1CjSIJaXuZyXdHO8v ...


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)

// Using text URL
Components.utils.importGlobalProperties(['File']);
let aFileURL = 'file:///C:/Users/***/icon.png'; // just an example
let file = File.createFromFileName(aFileURL);
// "File error: Unrecognized path"  nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)"

The following code works:

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);

The following code also works:

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);


Additional info for reference:

Using file = new File([], file.path); produces the following:

File { name: "C:\Users\...\icon.png", lastModified: 1487509240391, lastModifiedDate: Date 2017-02-19T13:00:40.391Z, webkitRelativePath: "", mozFullPath: "", size: 0, type: "" }

However, using file = File.createFromFileName(file.path); produces the following:

File { name: "icon.png", lastModified: 1403974172431, lastModifiedDate: Date 2014-06-28T16:49:32.431Z, webkitRelativePath: "", mozFullPath: "", size: 4294, type: "image/png" }

Using file = File.createFromNsIFile(file); produces the following:

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" }

Passing the file from the first code to FileReader() produces the wrong result. "data:application/octet-stream;base64,"

Passing the file from the 2nd & 3rd code to FileReader() produces the correct result. "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAQjUlEQVR42uWbB3QU17nHv7uzq60S6sJGotniARGYUCQcZAvkhh0QosZgXPJsHwgJpiTB4Aq4JrafwTHvkZeYBBt4EELAGAwGhABjwEYgcMExEk1CjSIJaXuZyXdHO8v..."

这篇关于Firefox 52“新文件”更改和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆