aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/blob
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/api/blob
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/zh-tw/web/api/blob')
-rw-r--r--files/zh-tw/web/api/blob/blob/index.html125
-rw-r--r--files/zh-tw/web/api/blob/index.html116
-rw-r--r--files/zh-tw/web/api/blob/size/index.html114
-rw-r--r--files/zh-tw/web/api/blob/type/index.html114
4 files changed, 469 insertions, 0 deletions
diff --git a/files/zh-tw/web/api/blob/blob/index.html b/files/zh-tw/web/api/blob/blob/index.html
new file mode 100644
index 0000000000..26fb1e8ef7
--- /dev/null
+++ b/files/zh-tw/web/api/blob/blob/index.html
@@ -0,0 +1,125 @@
+---
+title: Blob()
+slug: Web/API/Blob/Blob
+translation_of: Web/API/Blob/Blob
+---
+<p>{{APIRef("File API")}}</p>
+
+<p><code><strong>Blob()</strong></code> 建構式會回傳一個新建立的 {{domxref("Blob")}} 物件。新物件的內容是由 <em>array</em> 參數的成員值串連所構成。</p>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox">var aBlob = new Blob(<em> array</em>, <em>options</em> );
+</pre>
+
+<h3 id="參數">參數</h3>
+
+<ul>
+ <li><em>array</em> 可以是一個由 {{jsxref("ArrayBuffer")}}、{{domxref("ArrayBufferView")}}、{{domxref("Blob")}} 或 {{domxref("DOMString")}} 組成的 {{jsxref("Array")}} 物件,或是上述多種型別物件的混合陣列。這個陣列將會被放進新建立的 <code>Blob</code> 物件當中。DOMStrings 的編碼為 UTF-8。</li>
+ <li><em>option</em><em>s</em> 是選擇性的 <code>BlobPropertyBag</code> 字典物件,有以下兩個指定的屬性:
+ <ul>
+ <li><code>type</code> 屬性,預設值為空字串 <code>""</code>,表示將被放進 <code>Blob</code> 物件的陣列內容之 MIME 類型。</li>
+ <li><code>endings</code> 屬性,表示包含 <code>\n</code> 換行字元的字串要如何輸出,預設值為字串 <code>"transparent"</code>。此屬性值可為:<code>"native"</code>,代表換行字元會被轉為目前作業系統的換行字元編碼。也可以是 <code>"transparent"</code>,代表保留 <code>Blob</code> 物件中資料的換行字元。{{non-standard_inline}}</li>
+ </ul>
+ </li>
+</ul>
+
+<h2 id="範例">範例</h2>
+
+<pre class="brush: js language-js">var aFileParts = ['&lt;a id="a"&gt;&lt;b id="b"&gt;hey!&lt;/b&gt;&lt;/a&gt;']; // an array consisting of a single DOMString
+var oMyBlob = new Blob(aFileParts, {type : 'text/html'}); // the blob</pre>
+
+<h2 id="Specification" name="Specification">規範</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('File API', '#constructorBlob', 'Blob()')}}</td>
+ <td>{{Spec2('File API')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>
+ <p>基礎支援</p>
+ </td>
+ <td>20</td>
+ <td>{{CompatGeckoDesktop("13.0")}} [1]</td>
+ <td>10</td>
+ <td>12.10</td>
+ <td>8</td>
+ </tr>
+ <tr>
+ <td>在 Workers 中</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop("14.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>基礎支援</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile("13.0")}} [1]</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>在 Workers 中</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile("14.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 在 Firefox 16 以前,第二個參數若被設為 <code>null</code> 或 <code>undefined</code> 會導致錯誤而不是當成一個空鍵值。</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>廢棄的 {{domxref("BlobBuilder")}} 和取代他的建構子。</li>
+</ul>
+
+<p> </p>
diff --git a/files/zh-tw/web/api/blob/index.html b/files/zh-tw/web/api/blob/index.html
new file mode 100644
index 0000000000..457628556c
--- /dev/null
+++ b/files/zh-tw/web/api/blob/index.html
@@ -0,0 +1,116 @@
+---
+title: Blob
+slug: Web/API/Blob
+translation_of: Web/API/Blob
+---
+<p>{{APIRef("File API")}}</p>
+
+<p><code>Blob</code>(Binary Large Object)物件代表了一個相當於檔案(原始資料)的不可變物件。Blob 中的資料並不一定是 JavaScript 原生的格式。{{domxref("File")}} 介面基於 <code>Blob,</code>繼承 blob 並擴充其功能以支援操作使用者系統上的檔案。</p>
+
+<p>從其它非 Blob 物件或資料來建構 <code>Blob</code> 物件,可以使用 {{domxref("Blob.Blob", "Blob()")}} 建構式。要建立一個包含目前 blob 內容子集的 blob,可使用 {{domxref("Blob.slice()", "slice()")}} 方法。若要自使用者系統上的檔案取得 <code>Blob</code> 物件,請參考 {{domxref("File")}} 文件。</p>
+
+<p>接受 Blob 物件的 API 可以在 {{domxref("File")}} 上找到。</p>
+
+<div class="note">
+<p><strong>註:</strong>早期 <code>slice()</code> 方法擁有第二個參數 <code>length</code> 以指定在建立新 <code>Blob</code> 物件時要複製的位元組(byte)數量。假如指定的 <code>start + length</code> 超出了來源 <code>Blob</code> 的大小,則回傳的 <code>Blob</code> 會包含自索引 <code>start</code> 至結尾的完整來源內容。</p>
+</div>
+
+<div class="note">
+<p><strong>註:</strong>需注意在部分瀏覽器版本中,<code>slice()</code> 方法帶有前綴:Firefox 12 與之前的版本為 <code>blob.mozSlice()</code>,Safari 中是 <code>blob.webkitSlice()</code>。舊的、無前綴字版本的 <code>slice()</code> 方法則有不同的語意(semantics),但這是已淘汰的方法。瀏覽器對 <code>blob.mozSlice()</code> 的支援已在 Firefox 30 時中止。</p>
+</div>
+
+<h2 id="建構式">建構式</h2>
+
+<dl>
+ <dt>{{domxref("Blob.Blob", "Blob(blobParts[, options])")}}</dt>
+ <dd>回傳新建立的 <code>Blob</code> 物件,包含了建構式參數傳入之陣列所串聯後的值。第二個參數為 <font face="Consolas, Liberation Mono, Courier, monospace">BlobPropertyBag</font> <font face="Consolas, Liberation Mono, Courier, monospace">物件,其擁有</font> <code>type</code> 和 <code>endings</code> 屬性<font face="Consolas, Liberation Mono, Courier, monospace">。</font></dd>
+</dl>
+
+<h2 id="屬性">屬性</h2>
+
+<dl>
+ <dt>{{domxref("Blob.size")}} {{readonlyinline}}</dt>
+ <dd>以 byte 為單位的 <code>Blob</code> 物件大小。</dd>
+ <dt>{{domxref("Blob.type")}} {{readonlyinline}}</dt>
+ <dd><code>Blob</code> 物件中資料的型態,以 MIME 類型的字串表示。若型態為未知,則為空字串。</dd>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<dl>
+ <dt>{{domxref("Blob.slice()", "Blob.slice([start[, end[, contentType]]])")}}</dt>
+ <dd>回傳一個包含當前 <code>Blob</code> 物件之指定資料範圍(byte)內容的新 <code>Blob</code> 物件。</dd>
+</dl>
+
+<h2 id="範例">範例</h2>
+
+<h3 id="Blob_建構函數用法範例">Blob 建構函數用法範例</h3>
+
+<p>{{domxref("Blob.Blob", "Blob() constructor")}} 建構式允許由其它物件建立 blob 物件。以下的範例演示了以字串來建構 blob 物件:</p>
+
+<pre class="brush: js">var debug = {hello: "world"};
+var blob = new Blob([JSON.stringify(debug, null, 2)], {type : 'application/json'});</pre>
+
+<div class="warning">
+<p>在 Blob 建構式出現之前,可以透過 {{domxref("BlobBuilder")}} 來建立 blob 物件(目前已不建議使用):</p>
+
+<pre class="brush: js">var builder = new BlobBuilder();
+var fileParts = ['&lt;a id="a"&gt;&lt;b id="b"&gt;hey!&lt;/b&gt;&lt;/a&gt;'];
+builder.append(fileParts[0]);
+var myBlob = builder.getBlob('text/xml');</pre>
+</div>
+
+<h3 id="藉型別陣列建構的_blob_來建立_URL">藉型別陣列建構的 blob 來建立 URL</h3>
+
+<p>範例程式碼:</p>
+
+<pre class="brush: js">var typedArray = GetTheTypedArraySomehow();
+var blob = new Blob([typedArray], {type: 'application/octet-binary'}); // pass a useful mime type here
+var url = URL.createObjectURL(blob);
+// url will be something like: blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
+// now you can use the url in any context that regular URLs can be used in, for example img.src, etc.
+</pre>
+
+<h3 id="從_Blob_取出資料">從 Blob 取出資料</h3>
+
+<p>從 Blob 讀取資料的唯一方式就是使用 {{domxref("FileReader")}}。以下範例展示了讀取 Blob 內容作為型別陣列:</p>
+
+<pre class="brush: js">var reader = new FileReader();
+reader.addEventListener("loadend", function() {
+ // reader.result contains the contents of blob as a typed array
+});
+reader.readAsArrayBuffer(blob);</pre>
+
+<p>藉由操作 {{domxref("FileReader")}} 的其他方法,將 Blob 讀取成字串或是 data URL 是有可能的。</p>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">規範</th>
+ <th scope="col">狀態</th>
+ <th scope="col">註解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('File API','#blob','Blob')}}</td>
+ <td>{{Spec2('File API')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+
+
+<p>{{Compat("api.Blob")}}</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{domxref("BlobBuilder")}}</li>
+ <li>{{domxref("File")}}</li>
+ <li>{{domxref("URL.createObjectURL")}}</li>
+ <li><a href="/en-US/docs/Components.utils.importGlobalProperties">Components.utils.importGlobalProperties</a></li>
+</ul>
diff --git a/files/zh-tw/web/api/blob/size/index.html b/files/zh-tw/web/api/blob/size/index.html
new file mode 100644
index 0000000000..0abccad27d
--- /dev/null
+++ b/files/zh-tw/web/api/blob/size/index.html
@@ -0,0 +1,114 @@
+---
+title: Blob.size
+slug: Web/API/Blob/size
+tags:
+ - API
+ - Files
+ - Property
+ - Reference
+ - WebAPI
+ - 參考
+ - 屬性
+translation_of: Web/API/Blob/size
+---
+<div>{{APIRef("File API")}}</div>
+
+<p><strong><code>Blob.size</code></strong> 屬性回傳以 byte 為單位的 {{domxref("Blob")}} 或一個 {{domxref("File")}} 的大小。</p>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox">var sizeInBytes = <em>blob</em>.size
+</pre>
+
+<h2 id="值">值</h2>
+
+<p>一個數字。</p>
+
+<h2 id="範例">範例</h2>
+
+<pre class="brush:js">// fileInput 是個 HTMLInputElement: &lt;input type="file" multiple id="myfileinput"&gt;
+var fileInput = document.getElementById("myfileinput");
+
+// files 是個 FileList 物件 (類似 NodeList)
+var files = fileInput.files;
+
+for (var i = 0; i &lt; files.length; i++) {
+ console.log(files[i].name + " has a size of " + files[i].size + " Bytes");
+}</pre>
+
+<h2 id="規格">規格</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">規格</th>
+ <th scope="col">狀態</th>
+ <th scope="col">附註</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('File API', '#dfn-size', 'size')}}</td>
+ <td>{{Spec2('File API')}}</td>
+ <td>初定義</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>File.size</td>
+ <td>5</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("2")}}</td>
+ <td>10.0</td>
+ <td>11.10</td>
+ <td>5.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>File.size</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{domxref("Blob")}}</li>
+</ul>
diff --git a/files/zh-tw/web/api/blob/type/index.html b/files/zh-tw/web/api/blob/type/index.html
new file mode 100644
index 0000000000..ee2a231724
--- /dev/null
+++ b/files/zh-tw/web/api/blob/type/index.html
@@ -0,0 +1,114 @@
+---
+title: Blob.type
+slug: Web/API/Blob/type
+translation_of: Web/API/Blob/type
+---
+<div>{{APIRef("File API")}}</div>
+
+<p><a href="/en-US/docs/Web/API/Blob"><code>Blob</code></a> 物件的 <strong><code>type</code></strong> 屬性提供檔案的 <a href="https://developer.mozilla.org/zh-TW/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types">MIME 類別</a>。若無法辨明型別則回傳空字串。</p>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox">var mimetype = <var>instanceOfFile</var>.type</pre>
+
+<h2 id="值">值</h2>
+
+<p>一個字串。</p>
+
+<h2 id="範例">範例</h2>
+
+<pre class="brush:js">var i, fileInput, files, allowedFileTypes;
+
+// fileInput 是個 HTMLInputElement: &lt;input type="file" multiple id="myfileinput"&gt;
+fileInput = document.getElementById("myfileinput");
+
+// files 是個 FileList 物件 (類似 NodeList)
+files = fileInput.files;
+
+// 這範例接受 *.png, *.jpeg 和 *.gif 圖片。
+allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
+
+for (i = 0; i &lt; files.length; i++) {
+ // 測試 file.type 是否是允許的類別。
+ if (allowedFileTypes.indexOf(<strong>files[i].type</strong>) &gt; -1) {
+ // 若符合則執行這裡的程式碼。
+ }
+});
+</pre>
+
+<h2 id="規格">規格</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">規格</th>
+ <th scope="col">狀態</th>
+ <th scope="col">備註</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('File API', '#dfn-type', 'type')}}</td>
+ <td>{{Spec2('File API')}}</td>
+ <td>初定義</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>File.type</td>
+ <td>5</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("2")}}</td>
+ <td>10.0</td>
+ <td>11.10</td>
+ <td>5.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>File.type</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{domxref("Blob")}}</li>
+</ul>