From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/file/getastext/index.html | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 files/ja/web/api/file/getastext/index.html (limited to 'files/ja/web/api/file/getastext') diff --git a/files/ja/web/api/file/getastext/index.html b/files/ja/web/api/file/getastext/index.html new file mode 100644 index 0000000000..b0711a798d --- /dev/null +++ b/files/ja/web/api/file/getastext/index.html @@ -0,0 +1,84 @@ +--- +title: File.getAsText() +slug: Web/API/File/getAsText +tags: + - API + - File API + - Reference + - ファイル + - メソッド + - リファレンス + - 廃止 + - 非標準 +translation_of: Web/API/File/getAsText +--- +

{{APIRef("File API") }}{{non-standard_header}}

+ +

{{obsolete_header(7.0)}}

+ +

概要

+ +

getAsText メソッドは、テキストとして解釈されるファイルのデータを指定されたエンコーディングを使用して提供します。

+ +
+

メモ: このメソッドは廃止されています。代わりに {{domxref("FileReader")}} の {{domxref("FileReader.readAsText()","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
+    }
+  }
+}
+ +

仕様書

+ +

どの仕様書にも含まれていません。

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf