非標準
この機能は標準ではなく、標準化の予定もありません。公開されているウェブサイトには使用しないでください。ユーザーによっては使用できないことがあります。実装ごとに大きな差があることもあり、将来は振る舞いが変わるかもしれません。
Gecko 7.0 で廃止 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)
この機能は廃止されました。まだいくつかのブラウザーで動作するかもしれませんが、いつ削除されてもおかしくないので、使わないようにしましょう。
概要
getAsText
メソッドは、テキストとして解釈されるファイルのデータを指定されたエンコーディングを使用して提供します。
メモ: このメソッドは廃止されています。代わりに FileReader
の readAsText()
メソッドを使用してください。
構文
var str = instanceOfFile.getAsText(encoding);
引数
- encoding
- 返されるデータに使用するエンコーディングを示す文字列。この文字列が空の場合は、 UTF-8 が使用されます。
返値
指定された encoding
のテキストとして解釈されるファイルのデータを含む文字列。
例
// 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;
// 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.text.indexOf(file.mediaType) > -1) {
// file is of type text, which we accept
// make sure it's encoded as utf-8
var data = file.getAsText("utf-8");
// modify data with string methods
} else if (accept.binary.indexOf(file.mediaType) > -1) {
// binary
}
}
}
仕様書
どの仕様書にも含まれていません。