Book Image

Learning Google Apps Script

By : Ramalingam Ganapathy
Book Image

Learning Google Apps Script

By: Ramalingam Ganapathy

Overview of this book

Google Apps Script is a cloud-based scripting language based on JavaScript to customize and automate Google applications. Apps Script makes it easy to create and publish add-ons in an online store for Google Sheets, Docs, and Forms. It serves as one single platform to build, code, and ultimately share your App on the Web store. This book begins by covering the basics of the Google application platform and goes on to empower you to automate most of the Google applications. You will learn the concepts of creating a menu, sending mails, building interactive web pages, and implementing all these techniques to develop an interactive Web page as a form to submit sheets You will be guided through all these tasks with plenty of screenshots and code snippets that will ensure your success in customizing and automating various Google applications This guide is an invaluable tutorial for beginners who intend to develop the skills to automate and customize Google applications
Table of Contents (16 chapters)
Learning Google Apps Script
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Creating a file upload application


You can create an application to upload any file to Drive from the browser. Create the doGet and uploadFiles functions in the Code.gs file as listed here:

In the Code.gs file, add this code:

function doGet() {
  // Let's return html page created from the Form.html file.
  return HtmlService.createHtmlOutputFromFile('Form.html')
    .setTitle("File Upload");
};

function uploadFiles(form) {
  // You can change the folder name as you like.
  var folderName = "Uploaded Files";

  var folder, folders = DriveApp.getFoldersByName(folderName);
  
  // folders is an iterator.
  if (folders.hasNext()) folder = folders.next();
  // Let's create a folder if it does not exist.
  else folder = DriveApp.createFolder(folderName);
  
  // Let's create the file, got from the form, within the folder.
  var file = folder.createFile(form.file);

  // Let's return the file's url
  return file.getUrl();
}

The uploadFiles function looks for an existing folder with the name Uploaded...