Use [multipart: true] in Phoenix 1.6 HEEx template

After I upgraded to phoenix 1.6, I get an error using [multipart: true] under the form tag.

<.form let={f} for={:upload} action={Routes.audio_path(@socket, :upload)} options={[multipart: true]} >
 ...
<./form>

Error message:

#PID<0.22974.0> running ExampleWeb.Endpoint (connection #PID<0.22972.0>, stream id 1) terminated
Server: 0.0.0.0:5001 (http)
Request: GET /audios/new
** (exit) an exception was raised:
    ** (ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: {:multipart, true}
        (phoenix_html 3.1.0) lib/phoenix_html/safe.ex:81: Phoenix.HTML.Safe.List.to_iodata/1
        (phoenix_html 3.1.0) lib/phoenix_html/safe.ex:49: Phoenix.HTML.Safe.List.to_iodata/1
        (phoenix_html 3.1.0) lib/phoenix_html.ex:222: Phoenix.HTML.build_attrs/1
        (phoenix_html 3.1.0) lib/phoenix_html.ex:222: Phoenix.HTML.build_attrs/1
        (phoenix_html 3.1.0) lib/phoenix_html.ex:187: Phoenix.HTML.attributes_escape/1
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/helpers.ex:1033: anonymous fn/2 in Phoenix.LiveView.Helpers.form/1
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:387: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:486: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
        (elixir 1.12.2) lib/enum.ex:2385: Enum."-reduce/3-lists^foldl/2-0-"/3
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:387: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:658: Phoenix.LiveView.Diff.render_component/9
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:603: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
        (elixir 1.12.2) lib/enum.ex:2385: Enum."-reduce/3-lists^foldl/2-0-"/3
        (stdlib 3.15.2) maps.erl:410: :maps.fold_1/3
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:576: Phoenix.LiveView.Diff.render_pending_components/6
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/diff.ex:145: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/static.ex:234: Phoenix.LiveView.Static.to_rendered_content_tag/4
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/static.ex:126: Phoenix.LiveView.Static.render/3
        (phoenix_live_view 0.17.3) lib/phoenix_live_view/controller.ex:38: Phoenix.LiveView.Controller.live_render/3
        (phoenix 1.6.2) lib/phoenix/router.ex:355: Phoenix.Router.__call__/2tic.ex:234: Phoenix.LiveView.Static.to_rendered_content_tag/
1 Like

Hello and welcome,

Try this…

multipart={true}
4 Likes

Thanks for the help, saved me a few hours