-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LiveView support #71
Comments
I've currently used Waffle (without Waffle Ecto) with Phoenix LiveView. I followed the phoenix blog & screencast https://www.phoenixframework.org/blog/phoenix-live-view-upload-deep-dive with a few changes:
The rest was quite straightforward to implement :) |
@achedeuzot Could you please describe what issues did you have with |
@achempion Indeed, If I look at the code of Right now my steps are the following: I also couldn't see where I could call a custom Finally, the way the |
My app is completely written in LiveView. Doesn't seem like Waffle needs special support for LiveView. I followed this guide: And implemented the consume method like this. Note I have max_entries set to 1 so I'm only expecting one file.
|
Hi @achedeuzot, You can use waffle_ecto - I was able to get this working without changing my schema. You can construct a %Plug.Upload{} and pass it in to the changeset. Something like:
|
Hi @montebrown ! Thanks for your solution 🤗 My main issue was to find a way to properly manage the user update transaction as well as the possible errors of the validation and your solution is spot on, thanks ! I'll just need to raise in case of an My last issue to resolve now with |
Thanks @montebrown for your solution! For everybody who tried to get this working it is important to use the |
Thanks to everyone in the history above that helped me find my way with handling the file uploads with today's LiveView of 0.20.15. Given this:
The https://hexdocs.pm/phoenix_live_view/0.20.14/Phoenix.LiveView.html#consume_uploaded_entries/3 I found success with the following: # I have `max_entries: 1` set, the following expects only one `entry`:
def handle_event(
"save",
%{"schema" => schema_params},
socket
) do
[schema_params_with_image] =
consume_uploaded_entries(socket, :image, fn meta, entry ->
image_plug_upload =
%Plug.Upload{
content_type: entry.client_type,
filename: entry.client_name,
path: meta.path
}
updated_params =
Map.put(schema_params, "image", image_plug_upload)
{:postpone, updated_params}
end)
save_schema(
socket,
socket.assigns.action,
schema_params_with_image
)
end |
With the new upload functionality bundled in Phoenix LiveView, I wonder if anyone has successfully used Waffle with it, and if there are any gotchas or changes needed in the lib?
Info about LiveView uploads: https://hexdocs.pm/phoenix_live_view/uploads.html#content and https://hexdocs.pm/phoenix_live_view/uploads-external.html
The text was updated successfully, but these errors were encountered: