Class Blob
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
BLOB
Un objeto de intercambio de datos para los servicios de Apps Script.
Métodos obsoletos
Método | Tipo de datos que se muestra | Descripción breve |
getAllBlobs()
| Blob[] | Obtiene todos los objetos blob que se contienen en este objeto blob (posiblemente compuesto). |
Documentación detallada
copyBlob()
Muestra una copia de este blob.
Volver
Blob
: Es la copia nueva.
getAs(contentType)
Muestra los datos dentro de este objeto como un blob convertido al tipo de contenido especificado. Este método agrega la extensión adecuada al nombre del archivo, por ejemplo, "miarchivo.pdf". Sin embargo, se da por sentado que la parte del nombre de archivo que sigue al último punto (si corresponde) es una extensión existente que se debe reemplazar. Por lo tanto, "ShoppingList.12.25.2014" se convierte en "ShoppingList.12.25.pdf".
Para ver las cuotas diarias de conversiones, consulta Cuotas de los servicios de Google. Es posible que los dominios de Google Workspace recién creados estén sujetos temporalmente a cuotas más estrictas.
Parámetros
Nombre | Tipo | Descripción |
contentType | String | Es el tipo de MIME al que se debe realizar la conversión. Para la mayoría de los blobs, 'application/pdf' es la única opción válida. Para las imágenes en formato BMP, GIF, JPEG o PNG, también son válidos 'image/bmp' , 'image/gif' , 'image/jpeg' o 'image/png' . Para un documento de Documentos de Google, 'text/markdown' también es válido. |
Volver
Blob
: Los datos como un BLOB.
getBytes()
Obtiene los datos almacenados en este blob.
Volver
Byte[]
: Son los bytes almacenados.
getContentType()
Obtiene el tipo de contenido de los bytes de este blob.
Volver
String
: Es el tipo de contenido de estos datos, si se conoce, o null
.
getDataAsString()
Obtiene los datos de este blob como una cadena con codificación UTF-8.
Volver
String
: Son los datos como una cadena.
getDataAsString(charset)
Obtiene los datos de este objeto BLOB como una cadena con la codificación especificada.
Parámetros
Nombre | Tipo | Descripción |
charset | String | Es el conjunto de caracteres que se usará para codificar los datos de este blob como una cadena. |
Volver
String
: Son los datos como una cadena.
getName()
Obtiene el nombre de este blob.
Volver
String
: Es el nombre de estos datos, si se conoce, o null
.
isGoogleType()
Muestra si este blob es un archivo de Google Workspace (Hojas de cálculo, Documentos, etcétera).
Volver
Boolean
: Es true
si este blob es un archivo de Google Workspace; false
si no lo es.
setBytes(data)
Establece los datos almacenados en este blob.
Parámetros
Nombre | Tipo | Descripción |
data | Byte[] | Son los datos nuevos. |
Volver
Blob
: Este BLOB, para encadenar.
setContentType(contentType)
Establece el tipo de contenido de los bytes de este BLOB.
Parámetros
Nombre | Tipo | Descripción |
contentType | String | El nuevo contentType. |
Volver
Blob
: Este BLOB, para encadenar.
setContentTypeFromExtension()
Establece el tipo de contenido de los bytes de este blob según la extensión del archivo. El contentType es null
si no se puede adivinar a partir de su extensión.
Volver
Blob
: Este BLOB, para encadenar.
setDataFromString(string)
Establece los datos de este blob a partir de una cadena con codificación UTF-8.
Parámetros
Nombre | Tipo | Descripción |
string | String | Los datos de cadena. |
Volver
Blob
: Este BLOB, para encadenar.
setDataFromString(string, charset)
Establece los datos de este blob a partir de una cadena con la codificación especificada.
Parámetros
Nombre | Tipo | Descripción |
string | String | Los datos de cadena. |
charset | String | Es el conjunto de caracteres que se usará para interpretar la cadena como bytes. |
Volver
Blob
: Este BLOB, para encadenar.
setName(name)
Establece el nombre de este blob.
Parámetros
Nombre | Tipo | Descripción |
name | String | El nombre nuevo. |
Volver
Blob
: Este BLOB, para encadenar.
Métodos obsoletos
getAllBlobs()
Obsoleto. Esta función dejó de estar disponible y no se debe usar en secuencias de comandos nuevas.
Obtiene todos los objetos blob que se contienen en este objeto blob (posiblemente compuesto).
Volver
Blob[]
: Los blobs contenidos en el blob.
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-26 (UTC)
[null,null,["Última actualización: 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."]]