This topic was automatically generated from Slack. You can find the original thread here.
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?
To upload an array of URLs to Google Drive, you can use a loop within a code step in your Pipedream workflow. Here’s an example component that iterates over an array of URLs and uploads each one to Google Drive using the upload_file action: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, urls: { type: "string[]", label: "Array of URLs", }, }, async run({ steps, $ }) { const uploadedFiles = []; for (const url of this.urls) { // Download the file from the URL const response = await axios($, { method: "GET", url, responseType: "arraybuffer", }); // Upload the file to Google Drive const file = await this.google.drive.files.create({ requestBody: { name: url.split("/").pop(), mimeType: response.headers["content-type"], }, media: { mimeType: response.headers["content-type"], body: response.data, }, }); uploadedFiles.push(file); } return uploadedFiles; }, }); This component takes an array of URLs as input and uploads each file to Google Drive. Remember to connect your Google Drive account in the google prop.