Class Blob
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Blob
Objet d'échange de données pour les services Apps Script.
Méthodes obsolètes
Méthode | Type renvoyé | Brève description |
getAllBlobs()
| Blob[] | Récupère tous les blobs contenus dans ce blob (éventuellement composite). |
Documentation détaillée
copyBlob()
Renvoie une copie de ce blob.
Renvois
Blob
: nouvelle copie.
getAs(contentType)
Renvoie les données de cet objet sous forme de blob converti au type de contenu spécifié. Cette méthode ajoute l'extension appropriée au nom de fichier (par exemple, "monfichier.pdf"). Toutefois, il suppose que la partie du nom de fichier qui suit le dernier point (le cas échéant) est une extension existante qui doit être remplacée. Par conséquent, "ShoppingList.12.25.2014" devient "ShoppingList.12.25.pdf".
Pour afficher les quotas quotidiens pour les conversions, consultez la section Quotas pour les services Google. Les nouveaux domaines Google Workspace peuvent être temporairement soumis à des quotas plus stricts.
Paramètres
Nom | Type | Description |
contentType | String | Type MIME vers lequel effectuer la conversion. Pour la plupart des blobs, 'application/pdf' est la seule option valide. Pour les images au format BMP, GIF, JPEG ou PNG, les valeurs 'image/bmp' , 'image/gif' , 'image/jpeg' ou 'image/png' sont également valides. Pour un document Google Docs, 'text/markdown' est également valide. |
Renvois
Blob
: données sous forme de blob.
getBytes()
Récupère les données stockées dans ce blob.
Renvois
Byte[]
: octets stockés.
getContentType()
Récupère le type de contenu des octets de ce blob.
Renvois
String
: type de contenu de ces données, le cas échéant, ou null
.
getDataAsString()
Récupère les données de ce blob sous la forme d'une chaîne encodée en UTF-8.
Renvois
String
: données sous forme de chaîne.
getDataAsString(charset)
Récupère les données de ce blob sous la forme d'une chaîne avec l'encodage spécifié.
Paramètres
Nom | Type | Description |
charset | String | Encodage de caractères à utiliser pour encoder les données de ce blob sous forme de chaîne. |
Renvois
String
: données sous forme de chaîne.
getName()
Récupère le nom de ce blob.
Renvois
String
: nom de ces données, le cas échéant, ou null
.
isGoogleType()
Indique si ce blob est un fichier Google Workspace (Sheets, Docs, etc.).
Renvois
Boolean
: true
si ce blob est un fichier Google Workspace, false
sinon.
setBytes(data)
Définit les données stockées dans ce blob.
Paramètres
Nom | Type | Description |
data | Byte[] | Les nouvelles données. |
Renvois
Blob
: ce blob, pour le chaînage.
setContentType(contentType)
Définit le type de contenu des octets de ce blob.
Paramètres
Nom | Type | Description |
contentType | String | Nouveau contentType. |
Renvois
Blob
: ce blob, pour le chaînage.
setContentTypeFromExtension()
Définit le type de contenu des octets de ce blob en fonction de l'extension du fichier. La valeur contentType est null
si elle ne peut pas être devinée à partir de l'extension.
Renvois
Blob
: ce blob, pour le chaînage.
setDataFromString(string)
Définit les données de ce blob à partir d'une chaîne encodée en UTF-8.
Paramètres
Nom | Type | Description |
string | String | Données de chaîne. |
Renvois
Blob
: ce blob, pour le chaînage.
setDataFromString(string, charset)
Définit les données de ce blob à partir d'une chaîne avec l'encodage spécifié.
Paramètres
Nom | Type | Description |
string | String | Données de chaîne. |
charset | String | Encodage à utiliser pour interpréter la chaîne en tant qu'octets. |
Renvois
Blob
: ce blob, pour le chaînage.
setName(name)
Définit le nom de ce blob.
Paramètres
Nom | Type | Description |
name | String | Nouveau nom |
Renvois
Blob
: ce blob, pour le chaînage.
Méthodes obsolètes
getAllBlobs()
Obsolète. Cette fonction est obsolète et ne doit pas être utilisée dans les nouveaux scripts.
Récupère tous les blobs contenus dans ce blob (éventuellement composite).
Renvois
Blob[]
: blobs contenus dans le blob.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 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."]]