From 4ef33cb5a84fbdb93344909101aa72ca0a1e7493 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Wed, 13 May 2026 13:05:15 +0200 Subject: [PATCH 1/2] fix: create and update arke_file --- lib/arke/core/file.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/arke/core/file.ex b/lib/arke/core/file.ex index 49adee8..60dbd5f 100644 --- a/lib/arke/core/file.ex +++ b/lib/arke/core/file.ex @@ -81,7 +81,9 @@ defmodule Arke.Core.File do Map.update(unit, :data, unit.data, fn udata -> Map.put(udata, :public, is_public_file) end) case file_storage_module().upload_file("#{path}/#{name}", binary, public: is_public_file) do - {:ok, _object} -> {:ok, new_unit} + {:ok, _object} -> + clean_unit = Map.update(new_unit, :data, new_unit.data, fn udata -> Map.delete(udata, :binary_data) end) + {:ok, clean_unit} {:error, error} -> {:error, error} end end @@ -97,7 +99,9 @@ defmodule Arke.Core.File do def before_update(_, %{data: %{name: name, path: path, binary_data: binary}} = unit) do case file_storage_module().upload_file("#{path}/#{name}", binary) do - {:ok, _object} -> {:ok, unit} + {:ok, _object} -> + clean_unit = Map.update(unit, :data, unit.data, fn udata -> Map.delete(udata, :binary_data) end) + {:ok, clean_unit} {:error, error} -> {:error, error} end end From 1f26d5c232f4c9a10a9fcc41bd520441b0e9a540 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Wed, 13 May 2026 14:17:42 +0200 Subject: [PATCH 2/2] fix: handle remove binary on struct encode --- lib/arke/core/file.ex | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/arke/core/file.ex b/lib/arke/core/file.ex index 60dbd5f..0d3cbc1 100644 --- a/lib/arke/core/file.ex +++ b/lib/arke/core/file.ex @@ -56,18 +56,19 @@ defmodule Arke.Core.File do def on_struct_encode(arke, %{metadata: %{project: project}} = unit, data, opts) do load_files = Keyword.get(opts, :load_files, false) + clean_data = Map.delete(data, :binary_data) with true <- load_files, {:ok, %{signed_url: signed_url} = opts} <- get_url(unit) do - data = Map.put(data, :signed_url, signed_url) - {:ok, Map.put(data, :signed_url, signed_url)} + clean_data = Map.put(clean_data, :signed_url, signed_url) + {:ok, Map.put(clean_data, :signed_url, signed_url)} else false -> - {:ok, data} + {:ok, clean_data} {:error, msg} -> Logger.warn("error while loading the image: #{msg}") - {:ok, data} + {:ok, clean_data} end end @@ -81,9 +82,7 @@ defmodule Arke.Core.File do Map.update(unit, :data, unit.data, fn udata -> Map.put(udata, :public, is_public_file) end) case file_storage_module().upload_file("#{path}/#{name}", binary, public: is_public_file) do - {:ok, _object} -> - clean_unit = Map.update(new_unit, :data, new_unit.data, fn udata -> Map.delete(udata, :binary_data) end) - {:ok, clean_unit} + {:ok, _object} -> {:ok, new_unit} {:error, error} -> {:error, error} end end @@ -99,9 +98,7 @@ defmodule Arke.Core.File do def before_update(_, %{data: %{name: name, path: path, binary_data: binary}} = unit) do case file_storage_module().upload_file("#{path}/#{name}", binary) do - {:ok, _object} -> - clean_unit = Map.update(unit, :data, unit.data, fn udata -> Map.delete(udata, :binary_data) end) - {:ok, clean_unit} + {:ok, _object} -> {:ok, unit} {:error, error} -> {:error, error} end end