I am in the 30day try period of Google Apps for Work and i need to create a FORM accesible from all User of Domain, but I can't do it with Google Forms or Google Sites so I follow this guide
I try this with my personal account and it works, but when i repeat the process with GApps SuperAdmin accounts it doesn't work, I got this error: Exception: Access Denied: DriveApp.
Google Script
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.setDescription("Uploaded by " + form.myName);
return "File uploaded successfully " + file.getUrl();
}
catch (error) {
return error.toString();
}
}
HTML
<form id="myForm">
<input type="text" name="myName" placeholder="Your name..">
<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 id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
This is My "Deploy as Web App" configuration: here
I am open to every advice it is not necessary to use Google Script if there is a more reliable road
I tried the code, and it worked for me after turning on the Google drive apps @Greg mentioned in one of the comments.
For this setting in the Admin console go to: Google Apps > Drive > General Settings > and then check the box of "Allow users to install Google Drive apps"
Also with this code the files will be stored in the current user's drive and not in the admin's drive. To fix it you have to to the following:
Hope that helps.