将URL转换为FileReader.readAsDataURL的文件或Blob [英] Convert URL to File or Blob for FileReader.readAsDataURL
问题描述
考虑下面的例子:
$ $ $ $ $ $ $ $ $ $函数previewFile { b
var reader = new FileReader();
reader.onloadend = function(){
console.log(reader.result);
}
reader.readAsDataURL(file);
$ p
< blockquote>
instanceOfFileReader.readAsDataURL(blob);
blob:从中读取的Blob或文件。
-
本地文件URL如何可以:
'file:/// C:/ path- to / root.png'
是
传递给readAsDataURL()
-
是否可以在Firefox的插件中使用
FileReader()
?
-
是的,
FileReader
可用于插件。 How can a local file URL like:
'file:///C:/path-to/root.png'
be passed to thereadAsDataURL()
Is
FileReader()
available in a Firefox Addon?You can create
File
instances just by specifying a path when your code is chrome-privileged:new File("/path/to/file");
File
is a sub-class ofBlob
, so allFile
instances are also validBlob
s. Please note that this requires a platform path, and not a file URL.Yes,
FileReader
is available to addons.
File
个例,只需指定一个代码为chrome特权的路径: 新建文件(/ path / to / file);
文件是 Blob
,因此所有的 File
实例也是有效的 Blob
s。
请注意,这需要平台路径,而不是文件网址。
$ b
File
和 FileReader
/ code>秒。如果你想在非窗口范围内使用它们(比如 bootstrap.js
或者一个代码模块),你可以使用 nsIDOMFile
/ nsIDOMFileReader
。
Reference: FileReader.readAsDataURL
Considering the following example:
function previewFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
console.log(reader.result);
}
reader.readAsDataURL(file);
}
It states:
instanceOfFileReader.readAsDataURL(blob);
blob: The Blob or File from which to read.
File
and FileReader
are available in all window
s. If you want to use them in a non-window scope (like bootstrap.js
or a code module), you may use nsIDOMFile
/nsIDOMFileReader
.
这篇关于将URL转换为FileReader.readAsDataURL的文件或Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!