Blob:Blob() 建構子
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
備註: 此功能可在 Web Worker 中使用。
Blob()
建構子會回傳一個新的 Blob
物件。該 blob 的內容由參數 blobParts
中的值串接而成。
語法
js
new Blob(blobParts)
new Blob(blobParts, options)
參數
blobParts
選擇性-
一個可迭代的物件,例如
Array
,包含ArrayBuffer
、TypedArray
、DataView
、Blob
、字串,或這些元素的混合,這些元素將被放入Blob
中。字串應為格式良好的 Unicode,孤立的代理項會使用與String.prototype.toWellFormed()
相同的演算法進行清理。 options
選擇性-
一個物件,可以指定以下任一屬性:
type
選擇性-
將儲存到 blob 中的資料的 MIME 類型。預設值為空字串(
""
)。 endings
選擇性-
如果資料是文字,則如何解釋內容中的換行字元(
\n
)。預設值transparent
會將換行字元直接複製到 blob 中而不進行更改。若要將換行字元轉換為主機系統的本地慣例,請指定值native
。
回傳值
一個包含指定資料的新 Blob
物件。
範例
js
const blobParts = ['<q id="a"><span id="b">hey!</span></q>']; // 包含單一字串的陣列
const blob = new Blob(blobParts, { type: "text/html" }); // 該 blob
規範
Specification |
---|
File API> # constructorBlob> |
瀏覽器相容性
Loading…