Upload multiple files to Google Drive?

I have an array of URLs that I want to upload to Google Drive as files.
The Google Drive upload_file action works great for a single URL – but how do I iterate over my array and upload each one?

Hi @dzg,

To upload an array of URLs to Google Drive, you can use a loop in a code step to iterate over the array and call the Google Drive upload_file action for each URL. Here’s an example:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    google: {
      type: "app",
      app: "google",
    },
    urls: {
      type: "string[]",
      label: "Array of URLs",
    },
  },
  async run({ steps, $ }) {
    for (const url of this.urls) {
      const response = await axios($, {
        method: "GET",
        url,
        responseType: "arraybuffer",
      });

      const fileContent = Buffer.from(response.data, "binary");
      const fileName = url.split("/").pop();

      await this.google.drive.files.create({
        requestBody: {
          name: fileName,
          mimeType: response.headers["content-type"],
        },
        media: {
          mimeType: response.headers["content-type"],
          body: fileContent,
        },
      });
    }
  },
});

This code step takes an array of URLs as input, downloads each file, and uploads it to Google Drive using the upload_file action. Make sure to connect your Google account in the google prop.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.