How to Move Files Uploads from Google Forms to Specific Folders in Google Drive

0
5

To automatically move files uploaded via Google Forms to specific folders in Google Drive, you can use Google Apps Script, which allows you to create custom functions and automate tasks across Google products like Google Forms and Google Drive. Here’s a step-by-step guide to achieve this:

Step 1: Set Up Your Google Form

  1. Create Your Google Form:
    • Go to Google Forms (forms.google.com) and create a new form or open an existing one.
  2. Add File Upload Field:
    • Add a file upload question to your form where respondents can upload files.

Step 2: Get Form ID and Folder ID

  1. Form ID:
    • Open your Google Form.
    • In the URL of your form, the Form ID is the string of characters after /edit and before /view. Copy this ID.
  2. Folder ID:
    • Create a folder in Google Drive where you want to store the uploaded files.
    • Open this folder in Google Drive, and the Folder ID is the string of characters in the URL after folders/. Copy this ID.

Step 3: Create Google Apps Script

  1. Open Google Apps Script:
    • Go to script.google.com and create a new script.
  2. Replace Placeholder Code:
    • Replace the default code in the script editor with the following code:
javascript

function onFormSubmit(e) {
// Get response and item details
var form = FormApp.openById('YOUR_FORM_ID'); // Replace with your Form ID
var responses = form.getResponses();
var response = responses[responses.length - 1];
var itemResponses = response.getItemResponses();

// Iterate through responses
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
if (itemResponse.getItem().getType() === FormApp.ItemType.FILE_UPLOAD) {
var fileId = itemResponse.getResponse();
var file = DriveApp.getFileById(fileId);

// Move file to specific folder in Google Drive
var folderId = 'YOUR_FOLDER_ID'; // Replace with your Folder ID
var folder = DriveApp.getFolderById(folderId);
folder.createFile(file);

// Optionally, you can delete the file from the root folder after moving
// DriveApp.getRootFolder().removeFile(file);
}
}
}

  1. Modify Script:
    • Replace 'YOUR_FORM_ID' with the Form ID you copied earlier.
    • Replace 'YOUR_FOLDER_ID' with the Folder ID of the specific folder in Google Drive where you want to move the files.
  2. Save Script:
    • Save the script by clicking on the floppy disk icon or File -> Save.
  3. Set Triggers:
    • Click on the clock icon in the script editor toolbar to set up triggers.
    • Add a trigger for onFormSubmit to run the function when a form is submitted.
    • Configure the trigger to run onFormSubmit function as From form -> On form submit.

Step 4: Test Your Setup

  1. Test Form Submission:
    • Fill out your Google Form and upload a file.
    • Submit the form to trigger the script.
  2. Check Google Drive:
    • After submission, check the specified folder in Google Drive.
    • The uploaded file should appear in the designated folder.

Notes:

  • Permissions: Ensure that the Google account running the script has access to both the Google Form and the specified Google Drive folder.
  • Security: Google Apps Script runs with the permissions of the user who owns the script. Make sure you trust the script and its source.

By following these steps, you can automate the process of moving files uploaded via Google Forms to specific folders in Google Drive, streamlining your workflow and organization.

LEAVE A REPLY

Please enter your comment!
Please enter your name here