To upload a folder from Google Drive to a Google Cloud Storage (GCS) bucket using Google Apps Script, you can use the following code:

function uploadFolderToGCS() {
  // Set the folder ID of the Google Drive folder you want to upload
  var folderId = "DRIVE_FOLDER_ID";

  // Set the name of the GCS bucket you want to upload to
  var bucketName = "YOUR_BUCKET_NAME";

  // Get the folder by its ID
  var folder = DriveApp.getFolderById(folderId);

  // Get all the files in the folder
  var files = folder.getFiles();

  // Create a GCS bucket object
  var bucket = StorageApp.getBucket(bucketName);

  // Iterate through each file in the folder
  while (files.hasNext()) {
    var file =;

    // Get the file's data
    var data = file.getBlob();

    // Set the destination file name in the GCS bucket
    var destinationFileName = file.getName();

    // Upload the file to the GCS bucket
    bucket.createFile(data, destinationFileName);

Make sure to replace "DRIVE_FOLDER_ID" with the actual ID of the Google Drive folder you want to upload and "YOUR_BUCKET_NAME" with the name of your GCS bucket.

Please note that this script requires the “Google Apps Script API” and “Google Cloud Storage JSON API” to be enabled in your Google Cloud project. Also, ensure that the user executing the script has the necessary permissions to access the Google Drive folder and upload files to the GCS bucket.

Remember to set up the necessary credentials and permissions to access both Google Drive and Google Cloud Storage within your project.

Leave A Comment