Programming Phoenix LiveView: Live Uploads - I had to alter upload_static_file

When I first ran through the “Live Uploads” section, my images would upload and would be stored in the DB and “priv/static/images” directory, but they wouldn’t display properly because they were missing a file extension.

I had to update the upload_static_file function to look like this:

  defp upload_static_file(%{path: path}, entry) do
    filename = Path.basename(path) <> "_" <> entry.client_name  # <-- appended entry.client_name
    dest = Path.join("priv/static/images", filename) 
    File.cp!(path, dest)

    {:ok, ~p"/images/#{filename}"}
  end

Not sure if it’s a me problem or if there’s some other step that I missed, but felt I should flag it. Though I did notice that where it says:

Upload a product image in the browser and then open up a console with iex -S mix and query for the product you just updated with an image. You should see something like this:

The image_upload value also does not have a file extension, in the sample output in the book.

PS: again loving the book. Honestly for the first time I just read through the table of contents and I’m so excited for where this is going.