Solved it with the following extension code:
defp start_body_streaming(conn, io_device, target_path) do
parent = self()
spawn(fn ->
Process.monitor(parent)
receive do
{:DOWN, _ref, :process, _pid, {:shutdown, :local_closed}} ->
Logger.warning(
"File upload got interrupted for `#{target_path}`, deleting data received so far."
)
File.rm(target_path)
end
end)
stream_body(conn, io_device)
end
defp stream_body(conn, io_device) do
read_body(conn)
|> case do
{:ok, data, conn} ->
IO.binwrite(io_device, data)
{:ok, conn}
{:more, data, conn} ->
IO.binwrite(io_device, data)
stream_body(conn, io_device)
error ->
error
end
end


















