`"files"` and multipart HTTP actions: control over content-disposition
Isaac Bowen
We ran into an API that requires multipart POST requests having a part with headers like these:
Content-Disposition: form-data; name="file"; filename="file.csv"
Content-Type: text/csv
The
"files"
option in Mechanic's HTTP action uses hash keys as both name
and filename
for each file. There's no way direct way to use file generators and
end up with distinct name
vs filename
values.This future is about a direct path forward there.
In the meantime, something like this should work, as an indirect path:
{% assign boundary = "MechanicMultipartBoundary" %}
{% capture multipart_body %}
--{{ boundary }}
Content-Disposition: form-data; name="hello"
world
--{{ boundary }}
Content-Disposition: form-data; name="file"; filename="robots.csv"
Content-Type: text/csv
Sku Code,MRP,Cost Price
SKU1,0.00,0.00
SKU2,0.00,0.00
--{{ boundary }}--
{% endcapture %}
{% action "http" %}
{
"method": "post",
"url": "https://webhook.site/your-webhook-url",
"headers": {
"Content-Type": "multipart/form-data; boundary={{ boundary }}"
},
"body": {{ multipart_body | json }}
}
{% endaction %}