ไฟล์แนบ
เลิกใช้งานแล้ว คลาสนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่
ไฟล์แนบของ Sites เช่น ไฟล์ที่แนบอยู่กับหน้าเว็บ
โปรดทราบว่าไฟล์แนบคือ BLOB และสามารถใช้ได้ทุกที่ที่ต้องการอินพุต BLOB
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]);
getAttachmentType()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
แสดงประเภทของเอกสารแนบนี้ (HOSTED หรือ 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");
}
รีเทิร์น
AttachmentType
— ประเภทไฟล์แนบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
getContentType()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
แสดงประเภท MIME ของไฟล์แนบนี้ ไฟล์แนบในเว็บไม่สำเร็จ
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var contentType = attachments[0].getContentType();
รีเทิร์น
String
— ประเภท MIME ของไฟล์แนบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
getDatePublished()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
แสดงวันที่เผยแพร่ไฟล์แนบนี้เป็นครั้งแรก
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getDatePublished();
รีเทิร์น
Date
— วันที่เผยแพร่ครั้งแรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
getLastUpdated()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
แสดงวันที่อัปเดตไฟล์แนบครั้งล่าสุด
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var date = attachments[0].getLastUpdated();
รีเทิร์น
Date
— วันที่อัปเดตล่าสุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
getUrl()
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
แสดง URL ดาวน์โหลดของไฟล์แนบนี้
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
var url = attachments[0].getUrl();
รีเทิร์น
String
— URL สำหรับดาวน์โหลด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setContentType(contentType)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
ตั้งค่าประเภท MIME ของไฟล์แนบนี้ ไฟล์แนบในเว็บไม่สำเร็จ
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
var attachments = pages[0].getAttachments();
attachments[0].setContentType("text/plain");
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
contentType | String | ประเภท MIME ใหม่ |
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setDescription(description)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
กำหนดรายละเอียดของไฟล์แนบนี้
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");
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
description | String | คำอธิบายใหม่ |
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setFrom(blob)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
ตั้งค่าข้อมูลจริงของไฟล์แนบนี้ ไฟล์แนบในเว็บไม่สำเร็จ
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);
พารามิเตอร์
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setParent(parent)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
ตั้งค่าหน้าหลักของไฟล์แนบนี้
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]);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
parent | Page
| ผู้ปกครองใหม่ |
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setTitle(title)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
ตั้งชื่อไฟล์แนบนี้
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");
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
title | String | ชื่อใหม่ |
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds
setUrl(url)
เลิกใช้งานแล้ว ฟังก์ชันนี้เลิกใช้งานแล้วและไม่ควรใช้ในสคริปต์ใหม่ๆ
ตั้งค่า URL การดาวน์โหลดสำหรับไฟล์แนบนี้ ใช้ได้กับไฟล์แนบบนเว็บเท่านั้น
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");
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
url | String | |
รีเทิร์น
Attachment
— ไฟล์แนบนี้สำหรับการทำเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://sites.google.com/feeds