非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
Obsolete since Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
getAsBinary
method allows to access the file's data in raw binary format.
注意:
This method is obsolete; you should use the
FileReader
方法
readAsBinaryString()
or
readAsArrayBuffer()
代替。
var binary = instanceOfFile.getAsBinary();
A string.
// fileInput is an HTMLInputElement: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");
// files is a FileList object (similar to NodeList)
var files = fileInput.files;
// object for allowed media types
var accept = {
binary : ["image/png", "image/jpeg"],
text : ["text/plain", "text/css", "application/xml", "text/html"]
};
var file;
for (var i = 0; i < files.length; i++) {
file = files[i];
// if file type could be detected
if (file !== null) {
if (accept.binary.indexOf(file.type) > -1) {
// file is a binary, which we accept
var data = file.getAsBinary();
} else if (accept.text.indexOf(file.type) > -1) {
// file is of type text, which we accept
var data = file.getAsText();
// modify data with string methods
}
}
}
Not part of any specification.
File
getAsBinary()
getAsDataURL()
getAsText()