Skip to content

Commit f00c77c

Browse files
committed
fix default mp header for file with a form-data.
fix the issue found when testing the service wistia.com . spotted by @avdi on IRC.
1 parent ea5495a commit f00c77c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/hackney_multipart.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
-export([mp_header/2,
2323
mp_eof/1,
24+
part/3,
2425
len_mp_stream/2,
2526
mp_file_header/2,
2627
mp_mixed_header/2,
@@ -135,6 +136,12 @@ mp_header(Headers, Boundary) ->
135136
mp_eof(Boundary) ->
136137
<<"--", Boundary/binary, "--">>.
137138

139+
%% @doc create a part
140+
part(Content, Headers, Boundary) ->
141+
BinHeaders = hackney_headers:to_binary(Headers),
142+
<<"--", Boundary/binary, "\r\n", BinHeaders/binary, Content/binary,
143+
"\r\n" >>.
144+
138145
%% @doc get the size of a mp stream. Useful to calculate the
139146
%% content-length of a full multipart stream and send it as an identity
140147
%% transfer-encoding instead of chunked so any server can handle it.
@@ -199,8 +206,9 @@ mp_file_header({file, Path}, Boundary) ->
199206
mp_file_header({file, Path, []}, Boundary);
200207
mp_file_header({file, Path, ExtraHeaders}, Boundary) ->
201208
FName = hackney_bstr:to_binary(filename:basename(Path)),
202-
Disposition = {<<"file">>, [{<<"filename">>,
203-
<<"\"", FName/binary, "\"">>}]},
209+
Disposition = {<<"form-data">>,
210+
[{<<"name">>, <<"file">>},
211+
{<<"filename">>, <<"\"", FName/binary, "\"">>}]},
204212
mp_file_header({file, Path, Disposition, ExtraHeaders}, Boundary);
205213
mp_file_header({file, Path, {Disposition, Params}, ExtraHeaders}, Boundary) ->
206214
CType = hackney_bstr:content_type(Path),

0 commit comments

Comments
 (0)