Can Files be Sent with a Webhook Using a HTTP Request?

This topic was automatically generated from Slack. You can find the original thread here.

Hi! Is it possible to send files with a webhook, using a http request?

could you help?

Yes, I can help you with sending files using a webhook with an HTTP request. In Pipedream, you can use the axios library to send an HTTP request with a file attached. Here’s an example of how to send a file using a POST request with axios: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { url: { type: "string", label: "Webhook URL", }, filePath: { type: "string", label: "File Path", }, }, async run({ steps, $ }) { const fs = require("fs"); const FormData = require("form-data"); const form = new FormData(); form.append("file", fs.createReadStream(this.filePath)); const response = await axios($, { method: "POST", url: this.url, headers: form.getHeaders(), data: form, }); return response; }, }); This component takes two input props: url for the webhook URL and filePath for the path of the file you want to send. It reads the file using fs.createReadStream and appends it to a FormData object. Then, it sends a POST request to the webhook URL with the file attached. Please make sure to replace this.filePath with the actual path of the file you want to send.

That seemed a bit complicated. Is it an easier way to achieve this?