From c58d472801e58a5fe9ad9de199f1d84e3e66a4e3 Mon Sep 17 00:00:00 2001 From: Pascal Schmid Date: Wed, 23 Oct 2024 22:17:53 +0200 Subject: [PATCH] Make upload process stable The tmp dir phoenix liveview used for uploading the file was bound to that process. By copying the file to a save destination the upload process is stable again. --- .../live/components/file_input_component.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/mihainator_web/live/components/file_input_component.ex b/lib/mihainator_web/live/components/file_input_component.ex index 9efb021..268114a 100644 --- a/lib/mihainator_web/live/components/file_input_component.ex +++ b/lib/mihainator_web/live/components/file_input_component.ex @@ -21,7 +21,13 @@ defmodule MihainatorWeb.FileInputComponent do @impl true def handle_event("save", _params, socket) do consume_uploaded_entries(socket, :history, fn %{path: path}, _entry -> - Task.async(fn -> Mihainator.Extractor.extract(path) end) + dest = + System.tmp_dir!() + |> Path.join(Path.basename(path)) + + File.cp!(path, dest) + + Task.async(fn -> Mihainator.Extractor.extract(dest) end) {:ok, nil} end)