Local storage path does not match where the application searches
I am using arc to allow uploading and storing images for a post in my Phoenix web app. I am currently working with Local Storage. In my uploader I have set the storage directory:
# Override the storage directory:
def storage_dir(_version, {file, scope}) do
"uploads/microposts/pictures"
end
I also added plug MyApp.Plug.Static, at: "/uploads", from: {:my_app, "/uploads"} to my endpoint.ex file.
I uploaded a few files and saw that it created the "uploads" folder in the root directory of my app. But for some reason whenever the browser tried loading these images it would return a 404(Phoenix.Router.NoRouteError).
After some long debugging I found that Plug.Static was searching for these inside _/build/dev/lib/my_app/uploads instead of /uploads.
Unless I am doing something wrong. I would expect that Arc should by default (if using local storage), store files relative to where the application is running. Because Plug.Static creates the path with something like:
Path.join([Application.app_dir(app), "/uploads"])
which would not result in the root path where Arc is storing the files.
Is this a reasonable expectation? Or is there a better solution to my problem?
Similar issue, read below:
Absolute links for local urls #80
Add leading slash to urls generated from local adapter
Try this static plug instead:
plug Plug.Static,
at: "/uploads", from: Path.expand('./uploads'), gzip: false