|
21 | 21 |
|
22 | 22 | -export([mp_header/2, |
23 | 23 | mp_eof/1, |
| 24 | + part/3, |
24 | 25 | len_mp_stream/2, |
25 | 26 | mp_file_header/2, |
26 | 27 | mp_mixed_header/2, |
@@ -135,6 +136,12 @@ mp_header(Headers, Boundary) -> |
135 | 136 | mp_eof(Boundary) -> |
136 | 137 | <<"--", Boundary/binary, "--">>. |
137 | 138 |
|
| 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 | + |
138 | 145 | %% @doc get the size of a mp stream. Useful to calculate the |
139 | 146 | %% content-length of a full multipart stream and send it as an identity |
140 | 147 | %% transfer-encoding instead of chunked so any server can handle it. |
@@ -199,8 +206,9 @@ mp_file_header({file, Path}, Boundary) -> |
199 | 206 | mp_file_header({file, Path, []}, Boundary); |
200 | 207 | mp_file_header({file, Path, ExtraHeaders}, Boundary) -> |
201 | 208 | 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, "\"">>}]}, |
204 | 212 | mp_file_header({file, Path, Disposition, ExtraHeaders}, Boundary); |
205 | 213 | mp_file_header({file, Path, {Disposition, Params}, ExtraHeaders}, Boundary) -> |
206 | 214 | CType = hackney_bstr:content_type(Path), |
|
0 commit comments