arc icon indicating copy to clipboard operation
arc copied to clipboard

Local storage path does not match where the application searches

Open choncou opened this issue 9 years ago • 2 comments

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?

choncou avatar Nov 17 '16 16:11 choncou

Try this static plug instead:

  plug Plug.Static,
    at: "/uploads", from: Path.expand('./uploads'), gzip: false

ggerico avatar Nov 29 '16 02:11 ggerico