Hey, guys, I need some help to understand what is happening here, so I want to upload a file to Cloudinary, and I have everything set up but the error I’m facing is
** (ArgumentError) you attempted to apply :path on "beacon/company-logo/toiudkazny6rashasl3u". If you are using apply/3, make sure the module is an atom. If you are using the dot syntax, such as map.field or module.function, make sure the left side of the dot is an atom or a map
:erlang.apply("beacon/company-logo/toiudkazny6rashasl3u", :path, [])
(beacon) lib/beacon/upload.ex:8: Beacon.Upload.upload_attachement/4
(beacon) lib/beacon/account/company.ex:19: Beacon.Account.Company.changeset/2
(beacon) lib/beacon/account/user_actions.ex:117: Beacon.Account.UserActions.upsert_brand/1
My controller looks like this
def create(conn, %{"brand_logo" => brand_logo, "brand_color" => brand_color, "welcoming_message" => welcoming_message}) do
case UserActions.upsert_company(%{ brand_logo: brand_logo, brand_color: brand_color, welcoming_message: welcoming_message }) do
{:ok, brand_logo, brand_color, welcoming_message} ->
json conn, %{}
end
end
and the action in which I’m doing the insert_or_update into the database is
def upsert_company(attrs) do
case get_company_brand() do
nil -> %Company{}
company -> company
end
|> Company.changeset(attrs)
|> Repo.insert_or_update()
|> IO.inspect
end
schema is
schema "companies" do
field :brand_color, :string
field :brand_logo, :string
field :welcoming_message, :string
field :brand_logo_url, :string, virtual: true
timestamps()
end
def changeset(company, attrs) do
company
|> cast(attrs, [:brand_color, :brand_logo, :welcoming_message])
|> Upload.upload_attachement(attrs, :brand_logo, %{
tags: ["company-logo", "brand_logo"],
folder: Application.fetch_env!(:cloudex, :prefix) <> "/company-logo/",
})
|> validate_required([:brand_color])
end
Now I’m not sure why is he telling me that I want to apply path, I just want to save that id which is returning from the Cloudinary which is string, and later fetch it to display it in my template, so can someone please help me understand what I’m I doing wrong here, thanks.