You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking into using arc with phoenix to handle some images. Even though documentation is good enough, I am still confused about filename used in while storing a file and calling url method. General approach is to create a string field in database column and save file name into it. Even ecto_arc is built around same concept. So my question is, suppose I override filename method and make it dependent only model.uuid(actual uuid but not primary key) then why is it necessary to store filename in database in first place, or why is it required to pass filename while calling store or url methods. In my case filename serve no useful purpose. Shouldn't I able to do so by passing model as scope only?
Consider an example
schema "user" do
field :name, :string
field :email, :string
field :has_avatar, :boolean
field :has_cover, :boolean
timestamps()
end
defmodule Firefly.Files.Avatar do
use Arc.Definition
@versions [:original]
def filename(version, {_, scope}) do
"avatar_#{scope.uuid}"
end
def storage_dir(version, {file, scope}) do
"uploads/images/#{scope.uuid}/"
end
end
defmodule Firefly.Files.Cover do
use Arc.Definition
@versions [:original]
def filename(version, {_, scope}) do
"cover_#{scope.uuid}"
end
def storage_dir(version, {file, scope}) do
"uploads/images/#{scope.uuid}/"
end
end
Two boolean fields can tell if user has uploaded avatar and cover image.
Note: I am coming from Ruby on Rails and relatively new to Elixir eco system, so please forgive if I make some mistake or wrong assumption
The text was updated successfully, but these errors were encountered:
I was looking into using arc with phoenix to handle some images. Even though documentation is good enough, I am still confused about filename used in while storing a file and calling url method. General approach is to create a string field in database column and save file name into it. Even ecto_arc is built around same concept. So my question is, suppose I override
filename
method and make it dependent only model.uuid(actual uuid but not primary key) then why is it necessary to store filename in database in first place, or why is it required to pass filename while callingstore
orurl
methods. In my case filename serve no useful purpose. Shouldn't I able to do so by passing model as scope only?Consider an example
Two boolean fields can tell if user has uploaded avatar and cover image.
Note: I am coming from Ruby on Rails and relatively new to Elixir eco system, so please forgive if I make some mistake or wrong assumption
The text was updated successfully, but these errors were encountered: