Skip to content

Instantly share code, notes, and snippets.

@bennettscience
Created September 24, 2015 15:56
Show Gist options
  • Save bennettscience/72ff188e950ec22836fb to your computer and use it in GitHub Desktop.
Save bennettscience/72ff188e950ec22836fb to your computer and use it in GitHub Desktop.
Google Drive public dropbox upload
<html>
<body>
<div id="wrapper">
<h1>Student Work Submission</h1>
<form id="myForm">
<input type="text" name="myName" placeholder="Your name.." />
<select name="classPer">
<option>P1</option>
<option>P2</option>
<option>P3</option>
<option>P4</option>
<option>P6</option>
<option>P7</option>
</select>
<input type="file" name="myFile" />
<input type="submit" value="Upload File"
onclick="this.value='Uploading..';
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;" />
</form>
</div>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
h1 { font-family:Arial, Helvetica, sans-serif; }
body { width:50%; margin: 0 auto; font-size:30px;}
#wrapper { position: relative; width:100%; margin-top:50px;text-align:center; }
input, button, text, file { width:100%; height:auto; padding:10px 0; }
input { font-size:25px; }
input { display:block; margin:20px; }
select { width:100%; margin-left:20px;font-size:30px; }
#output { font-family:Helvetica,Arial,sans-serif; }
</style>
</body>
</html>
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var dropbox = "Student Files";
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
var blob = form.myFile;
var file = folder.createFile(blob);
file.setName(form.classPer + form.myName);
file.setDescription("Uploaded by " + form.myName);
Logger.log(form.myName);
return "File uploaded successfully. You can now close this window.";
} catch (error) {
return error.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment