-define(URL, "http://127.0.0.1:1000/"). -define(CRLF, "\r\n"). demo_upload_file() -> FileName = "/home/dash/avatar.png", {ok,Binary} = file:read_file(FileName), FieldName = "avatar", BinAccessToken = list_to_binary(AccessToken), BinFileName = list_to_binary(FileName), BinFieldName = list_to_binary(FieldName), Boundary = <<"upload_boundary">>, Body = <<"--", Boundary/binary, ?CRLF, "Content-Disposition: form-data; name=\"access_token\"", ?CRLF, ?CRLF, BinAccessToken/binary, ?CRLF, "--", Boundary/binary, ?CRLF, "Content-Disposition: form-data; name=\"", BinFieldName/binary, "\"; filename=\"", BinFileName/binary, "\"", ?CRLF, "Content-Type: application/octet-stream", ?CRLF, ?CRLF, Binary/binary, ?CRLF, "--", Boundary/binary, "--", ?CRLF, ?CRLF>>, ContentType = "multipart/form-data;boundary=upload_boundary", case httpc:request(post, {?Url, [], ContentType, Body}, [], []) of {ok, {_, _, Response}} -> Response; _ -> error end.
浙公网安备 33010602011771号