Passing additional metadata into live_file_input

Hi, I’m trying to pass metadata via live_file_input so i can pass details about what I’m uploading.

The use case for this is that I have a list of items, and I want to be able to upload files against those individual items. I want to be able to pass the id of the item I am uploading the file for so that I can associate the uploaded file with that item when it finishes uploading.

As far as I can tell, phx-value-* values aren’t passed into the Phoenix.LiveView.UploadEntry entries that are passed through to the functions, nor are there any fields in the structure to accept these. I’ve also tried placing it on the form, to no effect.

I suppose ideally I would be creating LiveComponents for each of these items, but unfortunately it looks like uploads aren’t supported on LiveComponents at this stage, so I’m looking for a workaround until that becomes a reality. (Upload events seemingly aren’t captured by the LiveComponent and are passed through to the parent LiveView I think).

Does anyone have any ideas or suggestions I may be able to try? Any help would be much appreciated.

My mistake; it looks like it should work within LiveComponents.

In case any one has similar problems, I had set the phx-target incorrectly; phx-target="@myself" instead of phx-target="<%= @myself %>". Oops!

1 Like