How can I pass the form and the field to Phoenix.Component.live_file_input/1?

Hi all,

how can I pass the form and the field to live_file_input/1 so that the name attribute is built correctly?

Thank you

Hi there, have you seen the LiveView guide on Uploads? In the guide’s example, the name attribute will be set to :avatar via the allow_upload/3 function.

@impl Phoenix.LiveView
def mount(_params, _session, socket) do
  {:ok,
   socket
   |> assign(:uploaded_files, [])
   |> allow_upload(:avatar, accept: ~w(.jpg .jpeg), max_entries: 2)}
end
<form id="upload-form" phx-submit="save" phx-change="validate">
  <.live_file_input upload={@uploads.avatar} />
  <button type="submit">Upload</button>
</form>
1 Like