非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

Deprecated since Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

摘要

The getAsDataURL provides a data: URL that encodes the entire contents of the referenced file.

注意: This method is obsolete; you should use the FileReader 方法 readAsDataURL() 代替。

句法

var url = instanceOfFile.getAsDataURL();
					

返回

A string representing a data: URL

范例

// fileInput is a HTMLInputElement: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");
// files is a FileList object (similar to NodeList)
var files = fileInput.files;
// array with acceptable file types
var accept = ["image/png"];
// img is a HTMLImgElement: <img id="myimg">
var img = document.getElementById("myimg");
// if we accept the first selected file type
if (accept.indexOf(files[0].mediaType) > -1) {
  // display the image
  // same as <img src="data:image/png,<imagedata>">
  img.src = files[0].getAsDataURL();
}
					

规范

Not part of any specification.

另请参阅

元数据

  • 最后修改: