aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/api/body/blob/index.html
blob: 53595fdbdae6f6e6c972a6444e86e3968cf44d70 (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
---
title: Body.blob()
slug: Web/API/Body/blob
translation_of: Web/API/Body/blob
---
<div>{{APIRef("Fetch")}}</div>

<p>Die Methode <strong><code>blob()</code></strong> des {{domxref("Body")}} Mixin nimmt einen {{domxref("Response")}} Stream und liest ihn bis zum Ende. Sie gibt ein Promise zurück, welches in einen {{domxref("Blob")}} aufgelöst wird.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush: js">response.blob().then(function(myBlob) {
  // mach etwas mit myBlob
});</pre>

<h3 id="Parameter">Parameter</h3>

<p>Keine.</p>

<div class="note"><strong>Hinweis:</strong> Wenn die {{domxref("Response")}} vom {{domxref("Response.type")}} her <code>"opaque"</code> ist, hat der resultierende {{domxref("Blob")}} eine {{domxref("Blob.size")}} von <code>0</code> und einen {{domxref("Blob.type")}} eines leeren Strings <code>""</code>, wodurch er für Methoden wie {{domxref("URL.createObjectURL")}} <em>unbrauchbar</em> wird.</div>

<h3 id="Rückgabewert">Rückgabewert</h3>

<p>Ein Promise, welches in einen {{domxref("Blob")}} aufgelöst wird.</p>

<h2 id="Beispiel">Beispiel</h2>

<p>In unserem <a href="https://github.com/mdn/fetch-examples/tree/master/fetch-request">Beispiel für eine Fetch Anfrage</a> (<a href="http://mdn.github.io/fetch-examples/fetch-request/">live ausführen</a>) erstellen wir eine neue Anfrage mit dem {{domxref("Request.Request")}} Konstruktor und rufen dann ein JPG ab. Wenn der Abruf erfolgreich ist, lesen wir mit <code>blob()</code> einen {{domxref("Blob")}} aus der Antwort, fügen ihn mit {{domxref("URL.createObjectURL")}} in eine Objekt-URL ein und legen diese URL als Quelle für das {{htmlelement("img")}} Element zum Anzeigen des Bildes fest.</p>

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

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

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

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Fetch','#dom-body-blob','blob()')}}</td>
   <td>{{Spec2('Fetch')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>



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

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li><a href="/de/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
 <li><a href="/de/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
 <li><a href="/de/docs/Web/HTTP">HTTP</a></li>
</ul>