aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/file/getasdataurl/index.html
blob: 4d7366549457bfe3d855002023e766b58da7f419 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
title: File.getAsDataURL()
slug: Web/API/File/getAsDataURL
tags:
  - API
  - File API
  - Obsolete
  - Reference
  - ファイル
  - メソッド
  - 廃止
  - 非標準
translation_of: Web/API/File/getAsDataURL
---
<div>{{APIRef("File API") }}</div>

<p>{{non-standard_header}}</p>

<p>{{deprecated_header(7.0)}}</p>

<h2 id="Summary" name="Summary">概要</h2>

<p>getAsDataURL は、参照されるファイルの内容全体をエンコードした <a href="/ja/docs/data_URIs"><code>data:</code></a> URL を提供します。</p>

<div class="note">
<p><strong>メモ:</strong> このメソッドは廃止されました。代わりに {{domxref("FileReader")}}{{domxref("FileReader.readAsDataURL","readAsDataURL()")}} メソッドを使用する必要があります。</p>
</div>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre>var url = <var>instanceOfFile</var>.getAsDataURL();</pre>

<h3 id="Returns" name="Returns">返値</h3>

<p><a href="/ja/docs/data_URIs"><code>data:</code></a> URL を表す文字列</p>

<h2 id="Example" name="Example"></h2>

<pre class="brush: js">// fileInput is a HTMLInputElement: &lt;input type="file" id="myfileinput" multiple&gt;
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: &lt;img id="myimg"&gt;
var img = document.getElementById("myimg");

// if we accept the first selected file type
if (accept.indexOf(files[0].mediaType) &gt; -1) {
  // display the image
  // same as &lt;img src="data:image/png,&lt;imagedata&gt;"&gt;
  img.src = files[0].getAsDataURL();
}
</pre>

<h2 id="Specification" name="Specification">仕様書</h2>

<p>どの仕様書にも含まれていません。</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{domxref("File")}}</li>
 <li>{{domxref("FileReader")}}</li>
</ul>