Attachment
Deprecated. This class is deprecated and should not be used in new scripts.
A Sites Attachment such as a file attached to a page.
Note that an Attachment is a Blob and can be used anywhere Blob input is expected.
var filesPage = SitesApp.getSite('example.com', 'mysite').getChildByName("files");
var attachments = filesPage.getAttachments();
// DocsList.createFile accepts a blob input. Since an Attachment is just a blob, we can
// just pass it directly to that method
var file = DocsList.createFile(attachments[0]);
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, "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. |
Return
Blob
— The data as a blob.
getAttachmentType()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the type of this attachment (HOSTED or WEB).
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var attType = attachments[0].getAttachmentType();
// This will log "Hosted"
Logger.log(attType);
// Since this returns an AttachmentType and not a String, for the
// purposes of equivalence we want to either do this or cast the
// type to a String
if(attType == SitesService.AttachmentType.HOSTED) {
Logger.log("This is a match");
}
// The above is the same as
if(String(attType) == "Hosted") {
Logger.log("This is also a match");
}
Return
AttachmentType
— the attachment type
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getContentType()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the mime type of this attachment. Fails for web attachments.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var contentType = attachments[0].getContentType();
Return
String
— the attachment mime type
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getDatePublished()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the date this attachment was first published.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getDatePublished();
Return
Date
— the date of original publication
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getDescription()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the description of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var description = attachments[0].getDescription();
Return
String
— the attachment description
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getLastUpdated()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the date this attachment was last updated.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getLastUpdated();
Return
Date
— the last updated date
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getParent()
Deprecated. This function is deprecated and should not be used in new scripts.
Get the parent page of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
// This is equal to pages[0]
var parent = attachments[0].getParent();
Return
Page
— the parent page
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getTitle()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the title of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var title = attachments[0].getTitle();
Return
String
— the attachment title
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
getUrl()
Deprecated. This function is deprecated and should not be used in new scripts.
Return the download url for this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var url = attachments[0].getUrl();
Return
String
— the download url
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
setContentType(contentType)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the mime type of this attachment. Fails for web attachments.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
attachments[0].setContentType("text/plain");
Parameters
Name | Type | Description |
contentType | String | the new mime type |
Return
Attachment
— this Attachment for chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
setDescription(description)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the descripton of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
// This is an example of chaining in action
attachments[0].setTitle("New Title")
.setDescription("New Description");
Parameters
Name | Type | Description |
description | String | the new description |
Return
Attachment
— this Attachment for chaining
Authorization
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.
var pages = SitesApp.getSite('demositeappsscript').getChildren();
var attachments = pages[0].getAttachments();
// This snippet demonstrates how to create a new text blob and attach it
// to the page
var blob = Utilities.newBlob("This data is now the attachment content");
// We must set a filename since we created the blob from String data
// instead of something like a URL source
blob.setName("attachment.txt");
attachments[0].setTitle("New Title")
.setDescription("New Description")
.setContentType("text/plain")
.setFrom(blob);
Parameters
Return
Attachment
— this Attachment for chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
setParent(parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the parent page of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
// Sets the parent page to be the next sibling
attachments[0].setParent(pages[1]);
Parameters
Name | Type | Description |
parent | Page
| the new parent |
Return
Attachment
— this Attachment for chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds
setTitle(title)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the title of this attachment.
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
// This is an example of chaining in action
attachments[0].setTitle("New Title")
.setDescription("New Description");
Parameters
Name | Type | Description |
title | String | the new title |
Return
Attachment
— this Attachment for chaining
Authorization
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.
var pages = SitesApp.getSite('demositeappsscript').getChildren();
var attachments = pages[0].getAttachments();
attachments[0].setTitle("New Web Attachment")
.setDescription("New Description")
.setUrl("http://example.com/files/your_file.txt");
Parameters
Name | Type | Description |
url | String | |
Return
Attachment
— this Attachment for chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://sites.google.com/feeds