Class Blob
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Blob
Apps Script 服務的資料交換物件。
內容詳盡的說明文件
copyBlob()
傳回此 Blob 的副本。
回攻員
Blob
:新副本。
getAs(contentType)
將此物件內的資料傳回為轉換為指定內容類型的 Blob。這個方法會在檔案名稱中加入適當的副檔名,例如「myfile.pdf」。不過,這會假設檔案名稱中最後一個句點 (如有) 後面的部分是應取代的現有副檔名。因此,「ShoppingList.12.25.2014」會變成「ShoppingList.12.25.pdf」。
如要查看轉換的每日配額,請參閱「Google 服務的配額」。新建立的 Google Workspace 網域可能會暫時受到較嚴格的配額限制。
參數
名稱 | 類型 | 說明 |
contentType | String | 要轉換的 MIME 類型。對於大多數 Blob 而言,'application/pdf' 是唯一有效的選項。如果是 BMP、GIF、JPEG 或 PNG 格式的圖片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 皆可用。如果是 Google 文件,'text/markdown' 也是有效的。 |
回攻員
Blob
:資料為 Blob。
getBytes()
取得儲存在此 Blob 中的資料。
回攻員
Byte[]
:已儲存的位元組。
getContentType()
取得此 Blob 中位元組的內容類型。
回攻員
String
:此資料的內容類型 (如果已知),或 null
。
getDataAsString()
以 UTF-8 編碼的字串格式,取得此 Blob 的資料。
回攻員
String
:資料以字串形式呈現。
getDataAsString(charset)
以指定的編碼方式,取得此 blob 的資料做為字串。
參數
名稱 | 類型 | 說明 |
charset | String | 用於將此 Blob 中的資料編碼為字串的字元集。 |
回攻員
String
:資料以字串形式呈現。
getName()
取得 Blob 的名稱。
回攻員
String
:如果已知這項資料的名稱,則為這項資料的名稱;否則為 null
。
isGoogleType()
傳回這個 Blob 是否為 Google Workspace 檔案 (試算表、文件等)。
回攻員
Boolean
:如果這個 Blob 是 Google Workspace 檔案,則為 true
;否則為 false
。
setBytes(data)
設定儲存在此 Blob 中的資料。
參數
回攻員
Blob
:這個 blob,用於鏈結。
setContentType(contentType)
設定此 blob 中位元組的內容類型。
參數
名稱 | 類型 | 說明 |
contentType | String | 新的 contentType。 |
回攻員
Blob
:這個 blob,用於鏈結。
setContentTypeFromExtension()
根據檔案副檔名,設定此 Blob 中位元組的內容類型。如果無法從擴充功能猜測 contentType,則為 null
。
回攻員
Blob
:這個 blob,用於鏈結。
setDataFromString(string)
從採用 UTF-8 編碼的字串,設定此 blob 的資料。
參數
回攻員
Blob
:這個 blob,用於鏈結。
setDataFromString(string, charset)
從使用指定編碼的字串中,設定此 blob 的資料。
參數
名稱 | 類型 | 說明 |
string | String | 字串資料。 |
charset | String | 用於將字串解讀為位元組的字元集。 |
回攻員
Blob
:這個 blob,用於鏈結。
setName(name)
設定此 Blob 的名稱。
參數
回攻員
Blob
:這個 blob,用於鏈結。
已淘汰的方法
getAllBlobs()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得此 (可能為複合) Blob 內含的所有 Blob。
回攻員
Blob[]
:Blob 內含的 Blob。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eA Blob is a data interchange object used for storing and manipulating binary data within Apps Script services.\u003c/p\u003e\n"],["\u003cp\u003eBlobs provide methods for setting, getting, and converting data in various formats, including bytes, strings, and specific content types.\u003c/p\u003e\n"],["\u003cp\u003eIt allows manipulation of data content, type, and name using dedicated methods.\u003c/p\u003e\n"],["\u003cp\u003eBlobs can handle Google Workspace files and offer functionalities for managing them within Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetAllBlobs()\u003c/code\u003e method is deprecated and should not be used in new scripts.\u003c/p\u003e\n"]]],[],null,["# Class Blob\n\nBlob\n\nA data interchange object for Apps Script services. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------|-------------|---------------------------------------------------------------------------------------|\n| [copyBlob()](#copyBlob()) | [Blob](#) | Returns a copy of this blob. |\n| [getAs(contentType)](#getAs(String)) | [Blob](#) | Return the data inside this object as a blob converted to the specified content type. |\n| [getBytes()](#getBytes()) | `Byte[]` | Gets the data stored in this blob. |\n| [getContentType()](#getContentType()) | `String` | Gets the content type of the bytes in this blob. |\n| [getDataAsString()](#getDataAsString()) | `String` | Gets the data of this blob as a String with UTF-8 encoding. |\n| [getDataAsString(charset)](#getDataAsString(String)) | `String` | Gets the data of this blob as a string with the specified encoding. |\n| [getName()](#getName()) | `String` | Gets the name of this blob. |\n| [isGoogleType()](#isGoogleType()) | `Boolean` | Returns whether this blob is a Google Workspace file (Sheets, Docs, etc.). |\n| [setBytes(data)](#setBytes(Byte)) | [Blob](#) | Sets the data stored in this blob. |\n| [setContentType(contentType)](#setContentType(String)) | [Blob](#) | Sets the content type of the bytes in this blob. |\n| [setContentTypeFromExtension()](#setContentTypeFromExtension()) | [Blob](#) | Sets the content type of the bytes in this blob based on the file extension. |\n| [setDataFromString(string)](#setDataFromString(String)) | [Blob](#) | Sets the data of this blob from a string with UTF-8 encoding. |\n| [setDataFromString(string, charset)](#setDataFromString(String,String)) | [Blob](#) | Sets the data of this blob from a string with the specified encoding. |\n| [setName(name)](#setName(String)) | [Blob](#) | Sets the name of this blob. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------|-------------|------------------------------------------------------------------------------|\n| [getAllBlobs()](#getAllBlobs()) | [Blob[]](#) | Gets all the blobs that are contained within this (possibly composite) blob. |\n\nDetailed documentation\n----------------------\n\n### `copy``Blob()`\n\nReturns a copy of this blob.\n\n#### Return\n\n\n[Blob](#) --- The new copy.\n\n*** ** * ** ***\n\n### `get``As(contentType)`\n\nReturn the data inside this object as a blob converted to the specified content type. This\nmethod adds the appropriate extension to the filename---for example, \"myfile.pdf\". However, it\nassumes that the part of the filename that follows the last period (if any) is an existing\nextension that should be replaced. Consequently, \"ShoppingList.12.25.2014\" becomes\n\"ShoppingList.12.25.pdf\".\n\nTo view the daily quotas for conversions, see [Quotas for Google\nServices](https://developers.google.com/apps-script/guides/services/quotas). Newly created Google Workspace domains might be temporarily subject to stricter\nquotas.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `content``Type` | `String` | The MIME type to convert to. For most blobs, `'application/pdf'` is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of `'image/bmp'`, `'image/gif'`, `'image/jpeg'`, or `'image/png'` are also valid. For a Google Docs document, `'text/markdown'` is also valid. |\n\n#### Return\n\n\n[Blob](#) --- The data as a blob.\n\n*** ** * ** ***\n\n### `get``Bytes()`\n\nGets the data stored in this blob.\n\n#### Return\n\n\n`Byte[]` --- The stored bytes.\n\n*** ** * ** ***\n\n### `get``Content``Type()`\n\nGets the content type of the bytes in this blob.\n\n#### Return\n\n\n`String` --- The content type of this data, if known, or `null`.\n\n*** ** * ** ***\n\n### `get``Data``As``String()`\n\nGets the data of this blob as a String with UTF-8 encoding.\n\n#### Return\n\n\n`String` --- The data as a string.\n\n*** ** * ** ***\n\n### `get``Data``As``String(charset)`\n\nGets the data of this blob as a string with the specified encoding.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-------------------------------------------------------------------|\n| `charset` | `String` | The charset to use in encoding the data in this blob as a string. |\n\n#### Return\n\n\n`String` --- The data as a string.\n\n*** ** * ** ***\n\n### `get``Name()`\n\nGets the name of this blob.\n\n#### Return\n\n\n`String` --- The name of this data, if known, or `null`.\n\n*** ** * ** ***\n\n### `is``Google``Type()`\n\nReturns whether this blob is a Google Workspace file (Sheets, Docs, etc.).\n\n#### Return\n\n\n`Boolean` --- `true` if this blob is a Google Workspace file; `false` if not.\n\n*** ** * ** ***\n\n### `set``Bytes(data)`\n\nSets the data stored in this blob.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|---------------|\n| `data` | `Byte[]` | The new data. |\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\n*** ** * ** ***\n\n### `set``Content``Type(contentType)`\n\nSets the content type of the bytes in this blob.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|----------|----------------------|\n| `content``Type` | `String` | The new contentType. |\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\n*** ** * ** ***\n\n### `set``Content``Type``From``Extension()`\n\nSets the content type of the bytes in this blob based on the file extension. The contentType is\n`null` if it cannot be guessed from its extension.\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\n*** ** * ** ***\n\n### `set``Data``From``String(string)`\n\nSets the data of this blob from a string with UTF-8 encoding.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|----------|------------------|\n| `string` | `String` | The string data. |\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\n*** ** * ** ***\n\n### `set``Data``From``String(string, charset)`\n\nSets the data of this blob from a string with the specified encoding.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|---------------------------------------------------------|\n| `string` | `String` | The string data. |\n| `charset` | `String` | The charset to use in interpreting the string as bytes. |\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\n*** ** * ** ***\n\n### `set``Name(name)`\n\nSets the name of this blob.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|---------------|\n| `name` | `String` | The new name. |\n\n#### Return\n\n\n[Blob](#) --- This blob, for chaining.\n\nDeprecated methods\n------------------\n\n### `get``All``Blobs()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nGets all the blobs that are contained within this (possibly composite) blob.\n\n#### Return\n\n\n[Blob[]](#) --- The blobs contained within the blob."]]