I am using Arc with Phoenix Channels and an external js client. I want to set the path based on room id.
E.g: room:5 => save file in uploads/rooms/5/
- Inside channel.ex
def handle_in("new_msg", params, socket) do
"room:" <> room = socket.topic
file_params = %{filename: params["filename"], binary: params["body"]}
file_params
|> decode_binary()
|> FileUploader.store()
end
defp decode_binary(params) do
Map.put(params, :binary, Base.decode64!(params.binary))
end
- Inside file_uploader.ex
use Arc.Definition
@versions [:original]
def __storage, do: Arc.Storage.Local
def storage_dir(version, {file, room_id}) do
"uploads/rooms/#{room_id}/"
end