I am currently using appscript with HTML service to populate a spreadsheet and upload a couple of files to a google drive. These files are images for which urls are not image links in google drive. Image links are only usable with files on google sites. So I need to convert this from uploading to drive to uploading to a folder on a google sites file cabinet page. All of the info I have found re: attachments to google sites are using the UI app which I am not interested in. I want to use the HTML service. Here is what I have which is fully functional:
Server .gs
var dropBoxId = "blablahbalh"; // Drive ID of 'dropbox' folder
var logSheetId = "blahblahbalh"; // Drive ID of log spreadsheet
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('myForm.html');
}
function uploadFiles(formObject) {
try {
// Create a file in Drive from the one provided in the form
var folder = DriveApp.getFolderById(dropBoxId);
var blob = formObject.myFile;
var blob2 = formObject.myFile2;
var file = folder.createFile(blob);
var file2 = folder.createFile(blob2);
file.setDescription("Uploaded by " + formObject.myName);
// Open the log and record the new file name, URL and name from form
var ss = SpreadsheetApp.openById(logSheetId);
var sheet = ss.getSheets()[0];
sheet.appendRow([file.getName(), file.getUrl(), file2.getName(),
file2.getUrl(), formObject.myName, formObject.actor_unions, formObject.actor_email, formObject.actor_phone, formObject.actor_website]);
// Return the new file Drive URL so it can be put in the web app output
return file.getUrl();
} catch (error) {
return error.toString();
}
}
HTML
<form id="myForm">
<input type="text" name="myName" placeholder="Your full name..."/>
<input type="text" name="actor_unions" placeholder="Union affiliations..."/>
<input type="text" name="actor_email" placeholder="email Address..."/>
<input type="text" name="actor_phone" placeholder="phone number..."/>
<input type="text" name="actor_website" placeholder="Website..."/>
<input name="myFile" type="file" />
<input name="myFile2" type="file" />
<input type="button" value="Submit"
onclick="google.script.run
.withSuccessHandler(updateUrl)
.withFailureHandler(onFailure)
.uploadFiles(this.parentNode)" />
</form>
<div id="output"></div>
<script>
function updateUrl(url) {
var div = document.getElementById('output');
div.innerHTML = '<a href="' + url + '">Upload successful!</a>';
}
function onFailure(error) {
alert(error.message);
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
console.log('message to print')in the browser, andLogger.log('my variable name: ' + variableName);in the script code to debug the code? Up to what point is the code working? Apps Script documentation - troubleshooting I deleted my last comment to save space. - Alan Wells