This topic was automatically generated from Slack. You can find the original thread here.
how can I attach a file to a webhook request that will be a trigger for a workflow?
This topic was automatically generated from Slack. You can find the original thread here.
how can I attach a file to a webhook request that will be a trigger for a workflow?
To attach a file to a webhook request that triggers a Pipedream workflow, you can make a multipart/form-data
HTTP request with the file as one of the form parts. Pipedream will save the file to an Amazon S3 bucket and generate a signed URL that allows you to access the file for up to 30 minutes. In workflows, these file URLs are provided in the steps.trigger.event.body
variable. Here’s an example of how to send a file using curl
: bash curl -X POST -H "Content-Type: multipart/form-data" -F "file=@/path/to/your/file" https://your-webhook-url.m.pipedream.net
Replace /path/to/your/file
with the actual file path and https://your-webhook-url.m.pipedream.net
with your workflow’s webhook URL. In your workflow, you can access the file URL using steps.trigger.event.body
. To download the file, you can use the axios
constructor from the @pipedream/platform
package. Here’s an example component that downloads the file to the /tmp
directory: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { const fileUrl = steps.trigger.event.body; const response = await axios($, { method: "GET", url: fileUrl, responseType: "stream", }); const filePath = `/tmp/${response.headers["content-disposition"].split("filename=")[1]}`; const writer = fs.createWriteStream(filePath); response.data.pipe(writer); return new Promise((resolve, reject) => { writer.on("finish", resolve); writer.on("error", reject); }); }, });
This component downloads the file from the URL and saves it to the /tmp
directory. You can then process the file within your workflow.
is there a file size limit for webhook requests?
Yes, there is a file size limit for webhook requests. By default, the body of HTTP requests sent to a workflow is limited to 100KB. However, you can send larger payloads or files using the large file upload interface. For files, you can make a multipart/form-data
HTTP request with the file as one of the form parts. Pipedream will save the file to an Amazon S3 bucket and generate a signed URL that allows you to access the file for up to 30 minutes. For more details on large file support, please refer to the documentation: Triggers