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, "ShoppingList.12.25.2014" becomes
"ShoppingList.12.25.pdf".
To view the daily quotas for conversions, see Quotas for Google
Services. Newly created Google Workspace domains might be temporarily subject to stricter
quotas.
Parameters
Name
Type
Description
contentType
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.
Scripts that use this method require authorization with one or more of the following scopes:
https://sites.google.com/feeds
getAttachmentType()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the type of this attachment (HOSTED or WEB).
varpages=SitesApp.getSite('example.com','mysite').getChildren();varattachments=pages[0].getAttachments();varattType=attachments[0].getAttachmentType();//Thiswilllog"Hosted"Logger.log(attType);//SincethisreturnsanAttachmentTypeandnotaString,forthe//purposesofequivalencewewanttoeitherdothisorcastthe//typetoaStringif(attType==SitesService.AttachmentType.HOSTED){Logger.log("This is a match");}//Theaboveisthesameasif(String(attType)=="Hosted"){Logger.log("This is also a match");}
Scripts that use this method require authorization with one or more of the following scopes:
https://sites.google.com/feeds
setFrom(blob)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the actual data of this attachment. Fails for web attachments.
varpages=SitesApp.getSite('demositeappsscript').getChildren();varattachments=pages[0].getAttachments();//Thissnippetdemonstrateshowtocreateanewtextblobandattachit//tothepagevarblob=Utilities.newBlob("This data is now the attachment content");//WemustsetafilenamesincewecreatedtheblobfromStringdata//insteadofsomethinglikeaURLsourceblob.setName("attachment.txt");attachments[0].setTitle("New Title").setDescription("New Description").setContentType("text/plain").setFrom(blob);
Scripts that use this method require authorization with one or more of the following scopes:
https://sites.google.com/feeds
setUrl(url)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the download url for this attachment. Only valid for web attachments.
varpages=SitesApp.getSite('demositeappsscript').getChildren();varattachments=pages[0].getAttachments();attachments[0].setTitle("New Web Attachment").setDescription("New Description").setUrl("http://example.com/files/your_file.txt");