Coding level: Beginner
Duration: 10 minutes
Project type: Automation with an event-driven trigger
About this solution
Simultaneously upload and organize files in Google Drive using Google Forms. The form includes inputs for the files to upload and for how the files should be organized.
How it works
A setup function creates a folder to store all uploaded files and a trigger that fires each time someone submits the form. When a user fills out the form, they choose files to upload and a subfolder to store the files in. Once the user submits the form, the script routes the files to the corresponding subfolder. If the folder doesn't exist yet, the script creates it.
Apps Script services
This solution uses the following services:
- Script Service: Creates the trigger that fires each time someone submits the form.
- Properties Service: Stores the ID of the trigger that the script creates during setup to prevent duplicate triggers.
- Drive Service: During setup, gets the form's location in Drive and creates a folder in the same location. When a user submits the form, Drive Service routes the files to that folder, and if selected, a designated subfolder. If the subfolder doesn't exist yet, the script creates it.
- Forms Service: Gets the files and folder name the user chose after they submit the form and sends it to Drive Service.
Before you begin
To use this sample, you need the following prerequisites:
- A Google Account (Google Workspace accounts might require administrator approval)
- A web browser with access to the internet
Step 1: Set up the Apps Script project
- Click the button below to copy the Upload files to Drive from Forms
Make a copy
- When prompted with the message, Missing file upload folders, click Restore.
- Click More > Script editor.
- In the editor, switch to the
- In the function dropdown, select
- Click Run.
- When prompted, authorize the script.
Step 2: Upload and store files
- Return to the form and click Preview .
- On the form, select a subfolder and upload a file. The sample form accepts PDFs and images. You can change the accepted file types in the form editor.
- Click Submit.
- Go to Drive and open the Upload files to Drive (File responses) folder. Your uploaded files are in the subfolder you selected on the form.
Open the Apps Script project
The sample script's code includes in-line comments to help you understand how it works. To access the code, in the form, click More > Script editor.
This sample is maintained by Google with the help of Google Developer Experts.