Phoenix plug change filename in body_params

I am implementing file uploads and use the arc + arc_ecto packages… after writing my proof of concept I am now trying to handle the file naming in a better way…The user uploads pictures and there is no need to keep the user given file name at all… therefore my idea is to write a simple plug that overwrites the user uploaded name with an uuid as a file name… problem is i can’t change the body params like this:

defp rename_file_uploads(conn = %Plug.Conn{:body_params => %{"offer" => %{"pic" => %Plug.Upload{:filename => filename}}}}, _) do
  put_in(conn, [:body_params, "offer", "pic", :filename], gen_unique_filename(filename))
end
defp rename_file_uploads(conn, _) do
  conn
end

what is the right way to do that?

is the uploaded image will be saved as file ? Could you just define a new name inside File.cp ?

I don’t use File.cp directly. This is handled by arc and by setting some file_name options inside the arc model I could already achieve the desired functionality but in a non ideal way (I have to save the generated uuid in my database and arc_ecto seems to save the original filename + a version string in the the database) to me this seems a little bit messy and I thought if I am never interested in the original filename, changing the params is maybe an easy and more simple way