I use arc and arc_ecto to load avatars for the model user. During development, I would like to use local storage. The download is in progress, but I don’t know how to actually display the image.
I can display the file name but don’t get the URL for local storage to use in the tag <img>. Should I use a different directory in the configuration or in a different way to access it in the view?
Web / templates / user / show.html.eex
<h2>Show user</h2>
[...]
<%= MyApp.Avatar.url({@user.avatar, @user}, :original) %>
Web / Uploaders / avatar.ex
defmodule MyApp.Avatar do
use Arc.Definition
use Arc.Ecto.Definition
@versions [:original, :thumb]
def transform(:thumb, _) do
{:convert, "-strip -thumbnail 100x100^ -gravity center -extent 100x100"}
end
def __storage, do: Arc.Storage.Local
def filename(version, {file, scope}), do: "#{version}-#{file.file_name}"
# Override the storage directory:
def storage_dir(version, {file, scope}) do
"web/static/assets/images/avatars/#{scope.id}"
end
end
source
share