Adding file uploads to our new poll UI

We have a nice uploads directory now, and we have a way for Phoenix to serve files out of that new directory, but we don't have a way for any of that to actually get into our application! We'll need to fix this by adding a file-handling functionality into our application. Let's start by updating our template. Open up lib/vocial_web/templates/poll/new.html.eex and add the following code just following to the options input:

<label>  Poll Image:  <%= file_input f, :image %></label><br />

You'll also need to return back to the form_for call at the top of that template and pass in the multipart option, set to true:

 <%= form_for @poll, poll_path(@conn, :create), [multipart: true], fn f -> %>

This will give ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.