Class Blob
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Blob
ออบเจ็กต์การแลกเปลี่ยนข้อมูลสําหรับบริการ Apps Script
วิธีการที่เลิกใช้งาน
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
getAllBlobs()
| Blob[] | รับ Blob ทั้งหมดที่อยู่ใน Blob นี้ (อาจเป็นแบบคอมโพสิต) |
เอกสารประกอบโดยละเอียด
copyBlob()
ส่งคืนสําเนาของ Blob นี้
รีเทิร์น
Blob
— สำเนาใหม่
getAs(contentType)
แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ วิธีนี้จะเพิ่มนามสกุลที่เหมาะสมลงในชื่อไฟล์ เช่น "myfile.pdf" อย่างไรก็ตาม ระบบจะถือว่าส่วนชื่อไฟล์ที่อยู่หลังจุดสุดท้าย (หากมี) เป็นนามสกุลที่มีอยู่ซึ่งควรแทนที่ ดังนั้น "ShoppingList.12.25.2014" จะเปลี่ยนเป็น "ShoppingList.12.25.pdf"
หากต้องการดูโควต้า Conversion รายวัน โปรดดูโควต้าสําหรับบริการของ 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()
รับข้อมูลของ Blob นี้เป็นสตริงที่เข้ารหัส UTF-8
รีเทิร์น
String
— ข้อมูลเป็นสตริง
getDataAsString(charset)
รับข้อมูลของ Blob นี้เป็นสตริงที่มีการเข้ารหัสที่ระบุ
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
charset | String | การเข้ารหัสที่จะใช้ในการเข้ารหัสข้อมูลในบล็อกนี้ให้เป็นสตริง |
รีเทิร์น
String
— ข้อมูลเป็นสตริง
getName()
รับชื่อของ Blob นี้
รีเทิร์น
String
— ชื่อของข้อมูลนี้ หากทราบ หรือ null
isGoogleType()
แสดงผลว่า Blob นี้เป็นไฟล์ Google Workspace หรือไม่ (ชีต เอกสาร ฯลฯ)
รีเทิร์น
Boolean
— true
หาก Blob นี้เป็นไฟล์ Google Workspace หรือ false
หากไม่ใช่
setBytes(data)
ตั้งค่าข้อมูลที่จัดเก็บไว้ใน Blob นี้
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
data | Byte[] | ข้อมูลใหม่ |
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
setContentType(contentType)
ตั้งค่าประเภทเนื้อหาของไบต์ใน Blob นี้
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
contentType | String | contentType ใหม่ |
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
setContentTypeFromExtension()
ตั้งค่าประเภทเนื้อหาของไบต์ในบล็อกนี้ตามนามสกุลไฟล์ contentType คือ null
หากไม่สามารถเดาได้จากนามสกุล
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
setDataFromString(string)
ตั้งค่าข้อมูลของ Blob นี้จากสตริงที่มีการเข้ารหัส UTF-8
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
string | String | ข้อมูลสตริง |
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
setDataFromString(string, charset)
ตั้งค่าข้อมูลของ Blob นี้จากสตริงที่มีการเข้ารหัสที่ระบุ
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
string | String | ข้อมูลสตริง |
charset | String | เซ็ตค่าอักขระที่จะใช้ในการตีความสตริงเป็นไบต์ |
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
setName(name)
ตั้งชื่อ Blob นี้
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
name | String | ชื่อใหม่ |
รีเทิร์น
Blob
— ข้อมูลก้อนนี้สําหรับการต่อเชื่อม
วิธีการที่เลิกใช้งาน
getAllBlobs()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรนำมาใช้ในสคริปต์ใหม่
รับ Blob ทั้งหมดที่อยู่ใน Blob นี้ (อาจเป็นแบบคอมโพสิต)
รีเทิร์น
Blob[]
— Blob ที่อยู่ภายใน Blob
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\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."]]