Skip to content

Instantly share code, notes, and snippets.

@bennettscience
Created August 14, 2015 20:08
Show Gist options
  • Save bennettscience/5336db9f9c048e47722e to your computer and use it in GitHub Desktop.
Save bennettscience/5336db9f9c048e47722e to your computer and use it in GitHub Desktop.
driveBox
/*
This is based on the template shared by Amit Agarwal (@labnol) on
the blog, Digital Inspiration. The original post with instructions:
http://www.labnol.org/internet/receive-files-in-google-drive/19697/
*/
// Find the form that is collecting the information to upload.
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
// Check for a folder called "Student Files" in Drive. If it's not there,
// create one.
try {
var dropbox = "Student Files";
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
// Once the folder is found, create the new file
// The file is named by attaching the Period Number to the Student Name.
var blob = form.myFile;
var file = folder.createFile(blob);
file.setName(form.classPer + form.myName);
// Display a success message to the user.
return "File uploaded successfully. You can now close this window.";
// If it fails, display the error message.
} catch (error) {
return error.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment