Setting Up a Google Drive to GCS Migration Flow

Migrate files from Google Drive to Google Cloud Storage for each tenant, preserving folder structures, handling Google file formats, and avoiding duplicate uploads based on file update timestamps.

1. Start the Flow

You can start the flow by selecting New API Request as the trigger.

Initiate Your Flow Variables

When the flow starts, the following important variables are initialized:

You also define MIME handling for Docs, Sheets, Slides, and Drawings so that Google-native files can be exported in the correct format during migration.


2. Configure Drive and GCS Settings

Map Get Configs

The next step maps values from your DriveConfigFlow so the flow has all required tenant and bucket details.

Create Bucket for Tenant

Once these values are ready, you can use the Google Cloud Storage connector to create a bucket for the tenant if it doesn’t already exist.


3. Set the File Path Rules

You will then hit a Switch step that determines how the filePath variable is set:

  • If baseFilePath is provided → set filePath = {{var.baseFilePath}}

  • If separateFoldersForUsers is true → set filePath per tenant/user

  • Else → set filePath = "Google Drive"

From here, you move into the Loop Over Input step.


4. Loop Over Input Items

For each item in your incoming list of file IDs:

  • Use the Google Drive connector with getFile

    • File ID = {{steps.loopOverInput.loopOverItem.value}}

    • param.fields = id,name,mimeType,modifiedTime

  • Initialize fileObject from loopOverItem

  • Append this file object to the files array using the advanced action insertItem.

You can click the three-dots next to your variable to setup or edit the advanced action selected.


5. Loop Over Files

After the Loop Over Input ends, the next step will be a loop that runs until all files are processed.

i. Initialize Loop Counters and Variables

  • Data Mapper: fileLength = arrayLength(var.files) ; total files in the queue.

Switch Statement

  • If no files remain, exit the loop.

  • Else, set:

    • currentFile = {{var.files[0]}} , the file you’ll process now.

    • Remove the first item from var.files using removeItem.

ii. Switch Statement to Check If Current File is a Folder

  • If currentFile.mimeType indicates a folder:

    • Call Google Drive Connector with action to getFilesFromFolder with:

      • param.q = '{{var.currentFile.file.id}}' in parents

      • param.fields = files(id,name,mimeType,modifiedTime)

    • Append each returned file to var.files so they’re picked up in the same loop.

Non-Folder Files

  • Build a state key for this file:

  • Read State for stateKey to check if the file is already processed or unchanged.

iii. Switch Step to Check if Files are Updated

Next Step is a switch statement that checks if files are updated, and ends the flow if there is no update.

If the file is updated,

  • Run gettingMimeType JS step → detect MIME type and extension.

function handler(params) {
  const mimeTypes = params?.data.var.mimeTypes;
  const fileMimeTypes = params?.data.var.currentFile.file.metadata?.mimeType;

  for (let i = 0; i < mimeTypes.length; i++) {
    if (mimeTypes[i].googleMimeType === fileMimeTypes) {
      return {
        mimeType: mimeTypes[i].exportableMimeTypes,
        extension: mimeTypes[i].exportablExtension
      };
    }
  }
  • Run preparingParams JS step → prepare download/export URLs.

function handler(params) {
  const fileId = params?.data.var.currentFile.file.value;
  let fileNamePrefix = '';
  if (params?.data.input.overrideFiles === false) {
    fileNamePrefix = Date.now() + '_';
  }

  return {
    googleUrl: 'https://www.googleapis.com/drive/v3/files/' + fileId + '/export?mimeType=' + params?.data.steps.gettingMimeType.output.mimeType,
    nonGoogleUrl: 'https://www.googleapis.com/drive/v3/files/' + fileId + '?alt=media',
    fileNamePrefix
  };
}
  • Get access token from Fastn Connector using the action getConnectorToken.

iv. Decide How to Download (Switch Step)

  • If Google-native file (Docs, Sheets, Slides, Drawings):

  • Else (non-Google file):

v. Download from Drive

  • For both types of files, the variables that are initialized will connect to the flow component Download file where you can download these files.

vi. Upload to Google Cloud Storage

  • In the next step, you will use the Google Cloud Storage connector with the action uploadFileToGCS with your target bucket and fileName.

vii. Update File State

  • In the next step, you will use the State component to overwrite the State for StateKey depending on the updates.

  • Loop picks up next currentFile and continues until var.files is empty.


6. Finish the Migration

The loop continues until all files are processed. When complete, the main flow returns a success message confirming the migration.

Last updated

Was this helpful?