{arc 0.5.2, arc_ecto 0.4.2} local_storage : odd behaviour of Phoenix.Router

Following the tutorial from smashingboxes.com I included in the endpoint.ex the following lines
plug Plug.Static,
at: "/uploads", from: Path.expand('./uploads'), gzip: false

Everything goes well, the schema works fine, the files are well saved, and I can see my pictures from the index template.
However when I go to the show template, Phoenix router in order to grab the asset is looking for the picture there GET /posts/uploads/post/thumbnails/1/picture.png instead of here /uploads/post/thumbnails/1/picture.png.
The links generated from the index and show templates by the arc function are identical : <img src="uploads/post/thumbnails/1/picture.png?v=63636129255">

I had to add these lines in the endpoint to help the router ^^:
plug Plug.Static,
at: "posts/uploads", from: Path.expand('./uploads'), gzip: false

Is it the expected behaviour of Phoenix router?

Tks,
G.

The generated links seem wrong. They should start with “/” at the beginning, so they are absolute path not dependent on wherever the user is inside the app. You should not have to hack on the plug.static path to make it work: the problem is with links themselves.

How do you generate the links in the template?

in the show template <img src="<%= MyApp.Thumbnail.url({@post.thumbnail, @post})%>"/>

well, I think this is this issue:

Quite frankly I don’t understand the behavior of arc. I think you could safely say that the local uploads simply do not work if this is happening and you should probably stick to using S3 instead. Or add “/” everywhere

1 Like