Search code examples
elixirphoenix-framework

HTTPoison timeout error while upload big file


I am trying to upload file by multipart form with my API. This works fine locally.

However when I deploy into the server it thrown and error calling the HTTPoison request for file size >30MB. I don’t have any issue if the file size is smaller.

Not sure what is going on.

Code:


{:ok, response} = HTTPoison.post(base_url(), body, header(), []) # <—- error on this line

case response.status_code do
200 ->
 data =
   response.body
   |> Jason.decode!()
   |> Map.get("outputs")
   |> List.first()

  {:ok, data}

  _ ->
  {:error, response.status_code}
end

Error:

{:error, %HTTPoison.Error{reason: :timeout, id: nil}}

Do I need to add recv_timeout to the option? If so can I add in runtime.exs file so easier for me to change in case?


Solution

  • You can use HTTPoison.Request.to_curl/1 to generate a curl command that can help you to debug. I would try setting a high value for the :recv_timeout option, e.g.

    HTTPoison.post(base_url(), body, header(), recv_timeout: :timer.seconds(30))