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/getasbinary/index.html | 77 ++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 files/ja/web/api/file/getasbinary/index.html (limited to 'files/ja/web/api/file/getasbinary') diff --git a/files/ja/web/api/file/getasbinary/index.html b/files/ja/web/api/file/getasbinary/index.html new file mode 100644 index 0000000000..e6b74acb06 --- /dev/null +++ b/files/ja/web/api/file/getasbinary/index.html @@ -0,0 +1,77 @@ +--- +title: File.getAsBinary() +slug: Web/API/File/getAsBinary +tags: + - API + - File API + - Reference + - ファイル + - メソッド + - 廃止 + - 非標準 +translation_of: Web/API/File/getAsBinary +--- +

{{APIRef("File API")}}

+ +

{{non-standard_header}}

+ +

{{obsolete_header(7.0)}}

+ +

概要

+ +

getAsBinary メソッドを使用すると、生のバイナリ形式でファイルのデータにアクセスできます。

+ +
+

メモ: このメソッドは廃止されました。代わりに{{domxref("FileReader")}} メソッドである {{domxref("FileReader.readAsArrayBuffer()","readAsArrayBuffer()")}}、もしくは {{domxref("FileReader.readAsBinaryString()","readAsBinaryString()")}}  を実行してください。

+
+ +

構文

+ +
var binary = instanceOfFile.getAsBinary();
+ +

返値

+ +

文字列です。

+ +

+ +
// fileInput is an HTMLInputElement: <input type="file" id="myfileinput" multiple>
+var fileInput = document.getElementById("myfileinput");
+
+// files は NodeList と似た FileList オブジェクトへの参照
+var files = fileInput.files;
+
+// 許容するメディアタイプを記したオブジェクト
+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 !== null) {
+    if (accept.binary.indexOf(file.type) > -1) {
+      // バイナリファイルの場合の処理
+      var data = file.getAsBinary();
+    } else if (accept.text.indexOf(file.type) > -1) {
+      // テキストファイルの場合の処理
+      var data = file.getAsText();
+      // String のメソッドでデータを加工する処理など…
+    }
+  }
+}
+ +

仕様書

+ +

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

+ +

関連情報

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