[erlang-questions] some help with hackney and multipart

Benoit Chesneau <>
Wed Mar 16 10:51:22 CET 2016


Sorry for the late answer, between traveling, recovering and welcome back
meetings I have been busy :)

The way the file is given is the standard way on the web. If you want to
pass another name, why not using the form:

({Name, Bin, ExtraHeaders},

If you really need to stream the file, a new pattern can be added I think.
Let me know what's you're trying to do.

- benoit


On Sat, Mar 12, 2016 at 9:02 PM Caragea Silviu <> wrote:

> I tested and what I see is that hackeny also use for files the name
> "file". I don't see how I can customize this as time mailgun search for
> attachment.
>
> Also looking to
> https://github.com/benoitc/hackney/blob/de35c1ec93dca89568b8b32cf053d82277a90762/src/hackney_multipart.erl
>
> line 228 this seems hard-coded:
>
> Disposition = {<<"form-data">>, [{<<"name">>, <<"\"file\"">>}, {<<"
> filename">>, <<"\"", FName/binary, "\"">>}]},
> Silviu
>
> On Wed, Mar 9, 2016 at 12:55 PM, Hynek Vychodil <>
> wrote:
>
>> Hi,
>> Try compare what is sent in body of request made by example with your one
>> sent by hackney
>>
>> curl -s --user 'api:YOUR_API_KEY' \
>>     https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
>>     -F from='Excited User <>' \
>>     -F to='' \
>>     -F cc='' \
>>     -F bcc='' \
>>     -F subject='Hello' \
>>     -F text='Testing some Mailgun awesomness!' \
>>     --form-string html='<html>HTML version of the body</html>' \
>>     -F attachment=@files/cartman.jpg \
>>     -F attachment=@files/cartman.png
>>
>> Your {multipart, PayloadBase ++ [{file, Attachment}]} doesn't make much
>> sense to me. Try something like {multipart, [{form, PayloadBase},{file,
>> Attachment}]} (untested).
>>
>> Hynek
>>
>> On Wed, Mar 9, 2016 at 11:31 AM, Caragea Silviu <>
>> wrote:
>>
>>>
>>>
>>> Hello,
>>>
>>> I'm trying to send an email via mailgun.com using the hackney and I
>>> have some issues sending attachments (which requires multipart).
>>>
>>> https://documentation.mailgun.com/api-sending.html#sending
>>>
>>> Basically my interest fields are:
>>>
>>>     from
>>>     to
>>>     subject
>>>     text
>>>     attachment File attachment. You can post multiple attachment values.
>>> Important: You must use multipart/form-data encoding when sending
>>> attachments.
>>>
>>> I tried the following:
>>>
>>> PayloadBase =[
>>>     {<<"from">>, From},
>>>     {<<"to">>, To},
>>>     {<<"subject">>, Subject},
>>>     {<<"text">>, TextBody},
>>>     {<<"html">>, HtmlBody}
>>> ],
>>>
>>> Payload = case Attachment of
>>>     null ->
>>>         {form, PayloadBase};
>>>     _->
>>>         {multipart, PayloadBase ++ [{file, Attachment}]}
>>> end,
>>>
>>> But for some reason the attachment is not sent.. Everything else works
>>> as expected.
>>> I don't see how I can set the filed name to "attachment" as required by
>>> mailgun .. at this this is what I suspect beeing wrong
>>>
>>> Silviu
>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160316/e9fd9683/attachment.html>


More information about the erlang-questions mailing list