aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/body/blob/index.html
blob: 1fb7cf8bbe646f53e0e12ac59d8ef70de5ea997f (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
69
70
71
72
73
74
75
76
77
78
79
---
title: Body.blob()
slug: Web/API/Body/blob
tags:
  - API
  - BODY
  - Blob
  - Experimental
  - Fetch
  - Method
  - Reference
translation_of: Web/API/Body/blob
---
<div>{{APIRef("Fetch")}}</div>

<p>{{domxref("Body")}} ミックスインの <strong><code>blob()</code></strong> メソッド は、 {{domxref("Response")}} ストリームを取得し、完全に読み込みます。 {{domxref("Blob")}} で解決する promise を返します。</p>

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

<pre class="syntaxbox"><em>response</em>.blob().then(function(<em>myBlob</em>) {
  // do something with myBlob
});</pre>

<h3 id="Parameters" name="Parameters">パラメーター</h3>

<p>なし。</p>

<div class="note"><strong></strong>: {{domxref("Response")}}{{domxref("Response.type")}}<code>"opaque"</code> の場合、結果の {{domxref("Blob")}}{{domxref("Blob.size")}}<code>0</code>{{domxref("Blob.type")}} は空の文字列 <code>""</code> になり、{{domxref("URL.createObjectURL")}} のようなメソッドでは役に立たなくなります。</div>

<h3 id="Return_value" name="Return_value">戻り値</h3>

<p>{{domxref("Blob")}} で解決する promise。</p>

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

<p><a href="https://github.com/mdn/fetch-examples/tree/master/fetch-request">fetch request の例</a><a href="http://mdn.github.io/fetch-examples/fetch-request/">fetch request をライブで</a>実行)では、{{domxref("Request.Request","Request()")}} コンストラクターを使用して新しいリクエストを作成し、それを使用して JPG をフェッチします。 フェッチが成功したら、<code>blob()</code> を使用してレスポンスから {{domxref("Blob")}} を読み取り、それを {{domxref("URL.createObjectURL")}} を使用してオブジェクト URL に入れ、その URL を {{htmlelement("img")}} 要素のソースとして設定して画像を表示します。</p>

<pre class="brush: js">var myImage = document.querySelector('img');

var myRequest = new Request('flowers.jpg');

fetch(myRequest)
.then(response =&gt; response.blob())
.then(function(myBlob) {
  var objectURL = URL.createObjectURL(myBlob);
  myImage.src = objectURL;
});
</pre>

<h2 id="Specifications" name="Specifications">仕様</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">仕様</th>
   <th scope="col">状態</th>
   <th scope="col">コメント</th>
  </tr>
  <tr>
   <td>{{SpecName('Fetch','#dom-body-blob','blob()')}}</td>
   <td>{{Spec2('Fetch')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>



<p>{{Compat("api.Body.blob")}}</p>

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

<ul>
 <li><a href="/ja/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
 <li><a href="/ja/docs/Web/HTTP/CORS">HTTP アクセス制御(CORS)</a></li>
 <li><a href="/ja/docs/Web/HTTP">HTTP</a></li>
</ul>