Skip to content

Commit

Permalink
Support unknown MIME types as filters for the file input (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored May 24, 2023
1 parent 74b4d71 commit 5c923b3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/livebook_web/live/output/file_input_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ defmodule LivebookWeb.Output.FileInputComponent do
else
socket
|> allow_upload(:file,
accept: socket.assigns.accept,
# The file input specifies the accepted formats, but in order
# to handle unknown MIME types, we need to pass :any to
# allow_upload and add the input accept attribute ourselves
accept: :any,
max_entries: 1,
progress: &handle_progress/3,
auto_upload: true
)
|> assign(initialized: true)
|> assign(
initialized: true,
accept:
case socket.assigns.accept do
:any -> nil
types when is_list(types) -> Enum.join(types, ",")
end
)
end

{:ok, socket}
Expand All @@ -44,7 +54,7 @@ defmodule LivebookWeb.Output.FileInputComponent do
Click to select a file or drag a local file here
<% end %>
</div>
<.live_file_input upload={@uploads.file} class="hidden" />
<.live_file_input upload={@uploads.file} class="hidden" accept={@accept} />
</label>
</form>
"""
Expand Down

0 comments on commit 5c923b3

Please sign in to comment.