Locally all my images are 404 not found (haven’t tried this in production). This is a brand new implementation so I’m sure I got something mixed up along the way.
I’m using ex_aws to store images in production, but locally I am just using the filesystem. I use system configs to determine what gets uploaded where.
dev.exs:
config :app, App.Images.PostImages,
provider: App.Storage.LocalProvider,
root: Path.expand(Path.join(__DIR__, "../priv/static/images/posts")),
url_prefix: "/pics"
LocalProvider:
@doc """
This is what fetches a URL of an uploaded image
"""
@impl true
def url(%{url_prefix: url_prefix}, key, _opts \\ []) do
with :ok <- validate_key(key) do
ok({:local, Path.join(url_prefix, key)})
else
res -> {:error, res}
end
end
endpoint.ex
image_file_storage = Application.get_env(:app, App.Images.PostImages)
if Keyword.fetch!(image_file_storage, :provider) == App.Storage.LocalProvider do
plug Plug.Static,
at: "/pics",
from: Keyword.fetch!(image_file_storage, :root),
gzip: false
end
The url/3 function returns a url /pics/:image_key, which it does. And I can view the image if I navigate to ../priv/static/images/posts/:image_key but Phoenix is not finding localhost:4000/pics/:image_key. What am I missing? I’ve implemented this in other systems before, but this is the first time I’ve written all provider behaviours myself.






















