Static files on production

388 views
Skip to first unread message

lee.sy...@gmail.com

unread,
Jan 9, 2016, 10:34:32 PM1/9/16
to phoenix-talk
Hi guys,

So, I've built a Phoenix app which works great locally.  The app uses file uploads and image manipulation.  The uploaded and converted files are stored in a directory in static, which is added to the allowed list in endpoint.ex.

When deployed to production, none of the files that are uploaded can be retrieved via a web request.  I get simply "page not found".  Now, if I upload a file to /static/images, I can't retrieve that, either.  It's almost like the production run app caches the files and serves those only.

Am I doing something silly?  What am I missing here?

Thanks,
Lee

lee.sy...@gmail.com

unread,
Jan 9, 2016, 11:07:17 PM1/9/16
to phoenix-talk, lee.sy...@gmail.com
So, I've run the app as dev on the server and everything works fine.  Ideally, it should run as production, though.

Lee

gery.de...@gmail.com

unread,
Jan 10, 2016, 2:17:01 AM1/10/16
to phoenix-talk, lee.sy...@gmail.com
I am not a Phoenix expert, but what you're doing seems horrible. Modifying an application code while it is running is definitely not the way you should do it.

A correct way in my opinion would be something like this:

1) define a File model in your application, it should have a field 'path' to your real file.
2) use that model everywhere in your UI you need to list your files.
3) when you want to read/send the actual file, use Elixir IO methods to read/manipulate it, and Phoenix/Plug methods to send it (like Plug,Conn.send_file/5)

This will be more robust to code upgrade, and should solve your issued.

lee.sy...@gmail.com

unread,
Jan 10, 2016, 2:36:37 AM1/10/16
to phoenix-talk, lee.sy...@gmail.com, gery.de...@gmail.com
Oh, this isn't a code issue.  These are just simple uploaded files that I've nested in the static directory.  What I'm trying to do is to retrieve these, via the static plug, but it doesn't seem to see them in production, only when run as dev.  The static plug should be able to serve me anything under the static directory, so long as I've whitelisted its directory in Endpoint.ex.

Lee

Chris McCord

unread,
Jan 10, 2016, 11:43:38 AM1/10/16
to phoeni...@googlegroups.com
You can remove your `cache_static_manifest` line in prod.exs, then your dynamically added static files will be served. We used the manifest in prod so we can cache the static lookup, which is expensive, so just keep the tradeoffs in mind when serving dynamic files out of priv/static.


-- 
You received this message because you are subscribed to the Google Groups "phoenix-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-talk...@googlegroups.com.
To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at https://groups.google.com/group/phoenix-talk.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-talk/6c7a7867-4bf2-48da-8d43-215e3dd07f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris McCord

unread,
Jan 10, 2016, 3:17:59 PM1/10/16
to phoeni...@googlegroups.com
Ignore me. It should work in both cases. Do you have an app that reproduces this that I can look at?

lee.sy...@gmail.com

unread,
Jan 10, 2016, 3:19:36 PM1/10/16
to phoenix-talk
Unfortunately, no.  However, even if I FTP a file to the images folder, I can't view it via URL when the app is running, so it should be easy to reproduce.

Lee

Chris McCord

unread,
Jan 10, 2016, 3:26:45 PM1/10/16
to phoeni...@googlegroups.com
Can you create a minimal sample app that reproduces the issue? It would help me diagnose.

Lee Sylvester

unread,
Jan 10, 2016, 3:34:29 PM1/10/16
to phoeni...@googlegroups.com
Sure thing.  I'll aim to get it built this evening after work.

Lee

--
You received this message because you are subscribed to a topic in the Google Groups "phoenix-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phoenix-talk/8Bmw75PLmck/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phoenix-talk...@googlegroups.com.

To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at https://groups.google.com/group/phoenix-talk.

nguyenvi...@gmail.com

unread,
Jan 27, 2016, 10:19:22 AM1/27/16
to phoenix-talk, lee.sy...@gmail.com
Hello, I have the same problem. I save the uploaded image file at /priv/static/images/ . I did remove the cache_sttic_manifest. but it does not help. 
```elixir
config :image_quick_share, ImageQuickShare.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [host: "example.com", port: 80]
# Do not print debug messages in production
config :logger, level: :info
```

ilya...@googlemail.com

unread,
Jun 18, 2017, 8:15:07 AM6/18/17
to phoenix-talk, lee.sy...@gmail.com
Hi, did you find a solution? I also ran into the same issue. I noticed that upload directory is being served only after server is stopped and then started again with MIX_ENV=prod mix compile && MIX_ENV=prod mix phoenix.server

воскресенье, 10 января 2016 г., 9:34:32 UTC+6 пользователь lee.sy...@gmail.com написал:
Reply all
Reply to author
Forward
0 new messages