--- title: BlobBuilder slug: Web/API/BlobBuilder translation_of: Web/API/BlobBuilder --- <p>{{ deprecated_header() }}</p> <p>{{ SeeCompatTable() }}</p> <p>The <code>BlobBuilder</code> interface provides an easy way to construct {{ domxref("Blob") }} objects. Just create a <code>BlobBuilder</code> and append chunks of data to it by calling the {{ manch("append") }} method. When you're done building your blob, call {{ manch("getBlob") }} to retrieve a {{ domxref("Blob") }} containing the data you sent into the blob builder.</p> <div class="note"> <strong>注:</strong><code>BlobBuilder</code>接口已经废弃,请使用新版草案中引入的 {{domxref('Blob') }}构造函数.</div> <h2 id="Method_overview" name="Method_overview">方法概述</h2> <table class="standard-table"> <tbody> <tr> <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in ArrayBuffer data);</code></td> </tr> <tr> <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in Blob data);</code></td> </tr> <tr> <td><code>void <a href="/zh-CN/DOM/BlobBuilder#append()" title="zh-CN/DOM/BlobBuilder#append()">append</a>(in String data, [optional] in String endings);</code></td> </tr> <tr> <td><code>Blob <a href="/zh-CN/DOM/BlobBuilder#getBlob()" title="zh-CN/DOM/BlobBuilder#getBlob()">getBlob</a>([optional] in DOMString contentType);</code></td> </tr> <tr> <td><code>File <a href="/zh-CN/DOM/BlobBuilder#getFile()" title="zh-CN/DOM/BlobBuilder#getFile()">getFile</a>(in DOMString name, [optional] in DOMString contentType);</code></td> </tr> </tbody> </table> <h2 id="方法">方法</h2> <h3 id="append()">append()</h3> <p>Appends the contents of the specified JavaScript object to the {{ domxref("Blob") }} being built. If the value you specify isn't a {{ domxref("Blob") }}, <a href="/zh-CN/JavaScript_typed_arrays/ArrayBuffer" title="zh-CN/JavaScript typed arrays/Arraybuffer"><code>ArrayBuffer</code></a>, or <a href="/zh-CN/JavaScript/Reference/Global_Objects/String" title="zh-CN/JavaScript/Reference/Global Objects/String"><code>String</code></a>, the value is coerced to a string before being appended to the blob.</p> <pre>void append( in ArrayBuffer data ); void append( in Blob data ); void append( in String data, [optional] in String endings ); </pre> <h6 id="参数">参数</h6> <dl> <dt> <code>data</code></dt> <dd> The data to append to the {{ domxref("Blob") }} being constructed.</dd> <dt> <code>endings</code></dt> <dd> Specifies how strings containing <code>\n</code> are to be written out. This can be <code>"transparent"</code> (endings unchanged) or <code>"native"</code> (endings changed to match host OS filesystem convention). The default value is <code>"transparent"</code>.</dd> </dl> <h3 id="getBlob()">getBlob()</h3> <p>Returns the {{ domxref("Blob") }} object that has been constructed using the data passed through calls to {{ manch("append") }}.</p> <pre class="eval">Blob getBlob( in DOMString contentType {{ optional_inline() }} ); </pre> <h6 id="参数_2">参数</h6> <dl> <dt> contentType {{ optional_inline() }}</dt> <dd> The MIME type of the data to be returned in the {{ domxref("Blob") }}. This will be the value of the <code>Blob</code> object's type property.</dd> </dl> <h6 id="返回值">返回值</h6> <p>A {{ domxref("Blob") }} object containing all of the data passed to any calls to {{ manch("append") }} made since the <code>BlobBuilder</code> was created. This also resets the <code>BlobBuilder</code> so that the next call to {{ manch("append") }} is starting a new, empty blob.</p> <h3 id="getFile()_non-standard_inline()">getFile() {{ non-standard_inline() }}</h3> <p>返回一个{{ domxref("File") }}对象.</p> <pre class="eval">File getFile( in DOMString name, [optional] in DOMString contentType ); </pre> <h6 id="参数_3">参数</h6> <dl> <dt> name</dt> <dd> 文件名.</dd> <dt> contentType {{ optional_inline() }}</dt> <dd> 设置返回的{{ domxref("File") }}对象中的数据的MIME类型.这个值将会成为返回<code>的File</code>对象的type属性的值.</dd> </dl> <h6 id="返回值_2">返回值</h6> <p>一个{{ domxref("File") }}对象.</p> <h2 id="浏览器兼容性">浏览器兼容性</h2> {{Compat("api.BlobBuilder")}} <h2 id="相关链接">相关链接</h2> <ul> <li>{{ spec("http://dev.w3.org/2009/dap/file-system/file-writer.html#idl-def-BlobBuilder", "File API Specification: BlobBuilder", "ED") }}</li> <li>{{ domxref("Blob") }}</li> <li>{{ domxref("File") }}</li> </ul>