My first workflow build already encountered setbacks. I am trying to automate uploading a file to a slack channel when that file gets added to a google drive folder. But, I am getting asked for a File path for /tmp. I do not know what this is, and my google searches have not turned up any information on what to put here. Where do I find this /tmp file path for a google drive folder?
Hi @jensenbm25,
I understand you want to upload a file to a Slack channel when it’s added to a Google Drive folder. To achieve this, you can use the Google Drive trigger “New File in Folder” and the Slack action “Upload File”.
First, add the “New File in Folder” trigger from the Google Drive app and select the folder you want to watch for new files. When a new file is added to the folder, the trigger will provide the file ID.
Next, add a code step to download the file from Google Drive to the /tmp
directory. Here’s an example code snippet:
import { axios } from "@pipedream/platform";
const fileId = steps.trigger.event.fileId;
const res = await axios(this.google.$auth, {
method: "GET",
url: `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`,
responseType: "stream",
});
const tmpFilePath = `/tmp/${fileId}`;
const writer = require("fs").createWriteStream(tmpFilePath);
res.data.pipe(writer);
await new Promise((resolve, reject) => {
writer.on("finish", resolve);
writer.on("error", reject);
});
Finally, add the “Upload File” action from the Slack app. In the File Path field, use the variable steps.<code_step_name>.return_value
(replace <code_step_name>
with the name of your code step) to reference the downloaded file’s path in the /tmp
directory.
Now, when a new file is added to the Google Drive folder, the workflow will download the file to /tmp
, and then upload it to the specified Slack channel.
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.