Create function for file_input (Without arc)

I need to create a function, where I can insert the full path of my image in my database …
I do not intend to use any library. Ex: Arc

How do I insert this path into my database?

When entering the form information, my inspect returns like this:

test_params = 
%{      
  "avatar" => %Plug.Upload{
    content_type: "image/png",
    filename: "test.png",
    path: "/tmp/plug-1586/multipart-1586737577-25205180440993-4"
  },
  "companyname" => "Test",
  "contactphone" => "00000000",
  "firstname" => "test1",
  "lastname" => "test2"
}

Could you help me create this role?
I am currently working on this function below.

def upload_route(conn, params) do
  if upload = params["avatar"] do
      user = Pow.Plug.current_user(conn)
      System.cmd("mkdir", ["priv/static/upload_client/#{user.id}"])
      File.cp(upload.path, "priv/static/upload_client/#{user.id}/#{upload.filename}") # your phoenix project dir
  end
end

I thought about using Repo.insert and get the url with conn.host

controller, function create.

  def create(conn, %{"test" => test_params}) do
    IO.inspect test_params
    changeset = Pow.Plug.current_user(conn)
    |> Ecto.build_assoc(:test)
    |> Profile.changeset(test_params)
    TestController.upload_route(conn, test_params)
      case Repo.insert(changeset) do
      {:ok, profile} ->
        conn
        |> put_flash(:info, "Test criado com sucesso.")
        |> redirect(to: Routes.test_path(conn, :show, test))

      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)
    end
  end
  def make_avatar_url(user_id, test_params) do
    with avatar_plug when not is_nil(avatar_plug) <- test_params["avatar"],
         user_uploads_path <- Path.expand("priv/static/upload_client/#{user_id}"),
         :ok <- File.mkdir_p(user_uploads_path),
         extension <- Path.extname(avatar_plug.filename),
         filename <- "avatar#{extension}",
         :ok <- File.cp(avatar_plug.path, "#{user_uploads_path}/#{filename}") do
      "/avatars/#{user_id}/#{filename}"
    else
      nil ->
        nil

      err ->
        err
    end
  end

  def create(conn, %{"profile" => test_params}) do
    user = Pow.Plug.current_user(conn)

    with avatar_url <- make_avatar_url(user.id, test_params),
         test_params <- Map.put(test_params, "avatar", avatar_url),
         changeset <-
           user
           |> Ecto.build_assoc(:test)
           |> Profile.changeset(test_params),
         {:ok, profile} <- Repo.insert(changeset) do
      conn
      |> put_flash(:info, "Test criado com sucesso.")
      |> redirect(to: Routes.profile_path(conn, :show, profile))
    else
      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)

      err ->
        conn
        |> put_flash(:error, "Test criado com error.")
        |> render("new.html", changeset: test_params, errors: err)
    end
  end

in lib\web\endpoint:

  plug Plug.Static,
    at: "/avatars",
    from: "priv/static/upload_client"

It was very good.
As I was thinking.

Helped me a lot.

How do you convert the image to a specific size?
300px 300px in size?

Check out Mogrify. You will need to install ImageMagic though.