   # adapter(Tesla.Adapter.Hackney)
   plug(Tesla.Middleware.JSON, decode: &JSON.decode/1, encode: &JSON.encode/1)
   plug(Tesla.Middleware.FollowRedirects)
-  # plug(Tesla.Middleware.Logger)
+  plug(Tesla.Middleware.Logger)
 
   def client do
+    adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]}
     binary_token = get_config_value(:string, "authorization", "token")
     server = get_config_value(:string, "authorization", "server")
     {:ok, _tkn} = JWT.decode(binary_token)


  def upload_image(image_filename, meta \\ %{}) do
    {:ok, changeset} = API.get_changeset(StorageAuth)
    storage_auth = %StorageAuth{form_data: form_data} = Ecto.Changeset.apply_changes(changeset)

    content_length = :filelib.file_size(image_filename)
    {:ok, pid} = Agent.start_link(fn -> 0 end)


    url = (uri.scheme || "https") <> "://" <> uri.host <> ":" <> to_string(uri.port)
    user_agent = "FarmbotOS/#{@version} (#{@target}) #{@target} ()"

    Tesla.client(
      [
        {Tesla.Middleware.BaseUrl, url},
        {Tesla.Middleware.Headers,
         [
           {"content-type", "application/json"},
           {"authorization", "Bearer: " <> binary_token},
           {"user-agent", user_agent}
         ]}
      ],
      adapter
    )
  end

  def storage_client(%StorageAuth{url: url}) do
    adapter = {Tesla.Adapter.Hackney, [recv_timeout: 30_000]}
    server = get_config_value(:string, "authorization", "server")
    uri = URI.parse(server)
    user_agent = "FarmbotOS/#{@version} (#{@target}) #{@target} ()"

    Tesla.client(
      [
        {Tesla.Middleware.FormUrlencoded, []},
        {Tesla.Middleware.BaseUrl, "#{uri.scheme}:#{url}"},
        {Tesla.Middleware.Headers,
         [
           {"user-agent", user_agent}
         ]}
      ],
      adapter
    )
  end

  @file_chunk 4096
