I have a file, such as junaid.jpeg.
I am reading it as data = File.read!("junaid.jpeg")
and I want to send that data as multipart data request using finch.
this is what my whole module looks like
defmodule EvercamFinch do
def request(method, url, headers \\ [], body \\ nil, opts \\ []) do
transformed_headers = tranform_headers(headers)
request = Finch.build(method, url, transformed_headers, body)
case Finch.request(request, __MODULE__, opts) do
{:ok, %Finch.Response{} = response} ->
{:ok, response}
{:error, reason} ->
{:error, reason}
end
end
defp tranform_headers([]), do: []
defp tranform_headers(headers) do
headers
|> Enum.map(fn({k, v}) ->
{Atom.to_string(k), v}
end)
end
end
and when I send this data, I am getting this error.
iex(5)> EvercamFinch.request(:post, "http://localhost:8888/test/junaid.png", ["Content-Type": "multipart/form-data"], data, [receive_timeout: 15_000])
{:ok,
%Finch.Response{
body: "{\"error\":\"no multipart boundary param in Content-Type\"}",
headers: [
{"content-type", "application/json"},
{"server", "SeaweedFS Filer 30GB 2.05"},
{"date", "Mon, 14 Dec 2020 17:47:28 GMT"},
{"content-length", "55"},
{"connection", "close"}
],
status: 500
}}
I am confused about how I can make a multipart request using finch(mint), is it supported or not? or how to make it work?