Google Apps Script

Class Blob

A data interchange object for Apps Script services.

Methods

MethodReturn typeBrief description
copyBlob()BlobReturns a copy of this blob.
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBytes()Byte[]Gets the data stored in this blob.
getContentType()StringGets the content type of the bytes in this blob.
getDataAsString()StringGets the data of this blob as a String with UTF-8 encoding.
getDataAsString(charset)StringGets the data of this blob as a string with the specified encoding.
getName()StringGets the name of this blob.
isGoogleType()BooleanReturns whether this blob is a Google Apps file (Sheets, Docs, etc.).
setBytes(data)BlobSets the data stored in this blob.
setContentType(contentType)BlobSets the content type of the bytes in this blob.
setContentTypeFromExtension()BlobSets the content type of the bytes in this blob based on the file extension.
setDataFromString(string)BlobSets the data of this blob from a string with UTF-8 encoding.
setDataFromString(string, charset)BlobSets the data of this blob from a string with the specified encoding.
setName(name)BlobSets the name of this blob.

Detailed documentation

copyBlob()

Returns a copy of this blob.

Return

Blob — the new copy


getAs(contentType)

Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename — for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ChristmasList.12.25.2014" will become "ChristmasList.12.25.pdf".

Parameters

NameTypeDescription
contentTypeStringthe 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.

Return

Blob — the data as a blob


getBytes()

Gets the data stored in this blob.

Return

Byte[] — the stored bytes


getContentType()

Gets the content type of the bytes in this blob.

Return

String — the content type of this data, if known, or null


getDataAsString()

Gets the data of this blob as a String with UTF-8 encoding.

Return

String — the data as a string


getDataAsString(charset)

Gets the data of this blob as a string with the specified encoding.

Parameters

NameTypeDescription
charsetStringthe charset to use in encoding the data in this blob as a string

Return

String — the data as a string


getName()

Gets the name of this blob.

Return

String — the name of this data, if known, or null


isGoogleType()

Returns whether this blob is a Google Apps file (Sheets, Docs, etc.).

Return

Booleantrue if this blob is a Google Apps file; false if not


setBytes(data)

Sets the data stored in this blob.

Parameters

NameTypeDescription
dataByte[]the new data

Return

Blob — this blob, for chaining


setContentType(contentType)

Sets the content type of the bytes in this blob.

Parameters

NameTypeDescription
contentTypeStringthe new contentType

Return

Blob — this blob, for chaining


setContentTypeFromExtension()

Sets the content type of the bytes in this blob based on the file extension. The contentType will be null if it cannot be guessed from its extension.

Return

Blob — this blob, for chaining


setDataFromString(string)

Sets the data of this blob from a string with UTF-8 encoding.

Parameters

NameTypeDescription
stringStringthe string data

Return

Blob — this blob, for chaining


setDataFromString(string, charset)

Sets the data of this blob from a string with the specified encoding.

Parameters

NameTypeDescription
stringStringthe string data
charsetStringthe charset to use in interpreting the string as bytes

Return

Blob — this blob, for chaining


setName(name)

Sets the name of this blob.

Parameters

NameTypeDescription
nameStringthe new name

Return

Blob — this blob, for chaining

Deprecated methods

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.