3. Loop Through the Files and Upload Them to Google Drive

In this lesson you’ll learn:

  • How to add a Loop (For Each) step to process multiple items

  • How to download each file from a URL

  • How to upload each file to the correct Google Drive folder

Introduction

In the previous lesson, we created an array of file URLs using the Code Step. Now it’s time to process each file individually by looping through the array.

Using the Loop (For Each) step, we can download each file and upload it directly to a Google Drive folder. This approach works whether the user uploaded one file or hundreds of files—your workflow will automatically handle them all!

Step 1: Create a Google Drive Folder for the Files

Before we start looping through the files, let’s create a dedicated folder in Google Drive to store them. This folder will be dynamically named using the patient’s Name and Date of Birth, ensuring all files stay organized under the correct patient record.

How to Create the Folder:

  1. Click the ➕ icon after the Code Step.

  2. Select the Google Drive connector and choose the Create Folder action.

  3. Configure the Folder Name field using dynamic data from the Jotform trigger:

    image 38.png
  4. Save and test the step to make the data of the folder available in your workflow and ensure that it works as expected.

Now that the folder is created, we’ll use it in the next step to store all uploaded files.

Step 2: Add a Loop (For Each) Step

  1. Click the ➕ icon after the Google Drive / Create folder step.

  2. Select For Each (Loop) from the Logic section.

  3. Configure the Loop:

    • Input Array: Map this to the files output from your Code Step.

  4. Save and Test the step: So each item from the array of files to be available inside the loop for further mapping to actions inside the loop. 

loop-1.gif

💡 Tip: The Loop will run once for each URL in the array. You can access the current item using the Loop Item variable in each step inside the loop.

Step 3: Download Each File

  1. Inside the Loop, click ➕ Add to loop to add a new step.

  2. Select the Jotform connector and the Download File from answer action.

  3. Map the File URL to the current Loop Item—this contains the URL for the current file being processed.

  4. Save the step.

    download file loop.gif

  5. Test the loop action again to download the files in Jotform and make their file URLs available for uploading to Google Drive.
    test loop 2.gif

     

    New File URLs

    As you can see from the test outputs, the "Download file from answer" step ran twice since there are two files in the form, and their ready-to-upload URLs became available in the workflow data.

    Frame 5.png

Learn more about files

You can check more on working with files inside a workflow in our article here.

Step 3: Upload the File to Google Drive

  1. After downloading the file, add another step inside the loop.

  2. Select the Google Drive connector and choose the Upload File action.

  3. Map the Folder input to be the folder id variable that is available from our previous step "Create folder" action.

  4. For the File input, map it to the URL variable that is available from the "Download file from answer" action inside our loop.
  5. Save the step.

upload-file-map.gif

Step 4: Test the Loop

  1. Select the "For Each" step in our workflow and click the "Test step" button for the loop to run once again and perform their inside actions.

  2. Verify that each file is downloaded and uploaded successfully to Google Drive.

  3. Check the Google Drive folder to confirm the files appear correctly.

Success!

Our workflow identified the two files the patient uploaded in Jotform, downloaded them, and uploaded them to their respective folder in Google Drive.

You’ve now automated the processing of multiple files, no matter how many the user submits.

image 40.png

Next Lesson

Now that you’ve mastered looping through files, let’s take automation even further by making a custom HTTP API call to DrChrono for an advanced action that’s not yet supported in Keragon.

Next Lesson: Make a Custom HTTP API Call using the HTTP connector

Was this article helpful?
0 out of 0 found this helpful

Articles in this section