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...