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]);
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");
}
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var contentType = attachments[0].getContentType();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getDatePublished();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var description = attachments[0].getDescription();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getLastUpdated();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
// This is equal to pages[0]
var parent = attachments[0].getParent();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var title = attachments[0].getTitle();
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
attachments[0].setContentType("text/plain");
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");
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);
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]);
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");
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");