Upload files to Google Drive from Google Forms

Stay organized with collections Save and categorize content based on your preferences.

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.

Screenshot of form to upload files

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

Try it

Step 1: Set up the Apps Script project

  1. Click the button below to copy the Upload files to Drive from Forms form.
    Make a copy
  2. When prompted with the message, Missing file upload folders, click Restore.
  3. Click More > Script editor.
  4. In the editor, switch to the Setup.gs file.
  5. In the function dropdown, select setUp.
  6. Click Run.
  7. When prompted, authorize the script. If the OAuth consent screen displays the warning, This app isn't verified, continue by selecting Advanced > Go to {Project Name} (unsafe).

Step 2: Upload and store files

  1. Return to the form and click Preview Preview icon.
  2. 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.
  3. Click Submit.
  4. 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.