Why Phoenix not serve mp4 video as static?

137 views
Skip to first unread message

Roland P

unread,
Apr 5, 2017, 7:57:26 PM4/5/17
to phoenix-talk
Hello everyone! Phoenix serve any files from privat static includeing css/app.css but when on adreess browser 1 write http://127.0.0.1:4000/11.mp4  its answered me that route 11.mp4 not found, but if wrote http://127.0.0.1:4000/robots.txt its out that file on browser. robotsd.txt and 11.mp4 are both on priv/static whats wrong?

Justin Wood

unread,
Apr 5, 2017, 9:16:17 PM4/5/17
to phoenix-talk
In your endpoint file, you will have the configuration for the static plug (the thing that serves your static files). By default, it should look something like

plug Plug.Static,
  at: "/", from: :my_app, gzip: false,
  only: ~w(css fonts images js favicon.ico robots.txt)

You are going to want to add an entry to the list of either 11.mp4 or a folder that contains all of your video files.

er...@scouten.com

unread,
Apr 8, 2017, 4:28:42 PM4/8/17
to phoenix-talk
What Justin said in his reply is true, but there's more to this story:

Some browsers (notably Safari on both Mac and iOS) require that the server support HTTP range requests in order to play back video files. (See https://tools.ietf.org/html/rfc7233 for the gory details of how range requests work.)

Plug.Static does not currently support range requests, so video files (MP4, MOV, etc.) will not play correctly in Safari (known issue: written up as https://github.com/elixir-lang/plug/issues/523). Note that this is a Plug issue, not Phoenix, but since Phoenix depends on Plug, it seems reasonable to discuss it here. I have a pull request pending against Plug that addresses this issue (https://github.com/elixir-lang/plug/pull/526), but there is still work I need to do before it is ready to merge. I've had to set it aside for work on other projects, but hope to get back to it soon.

Two things you could do to help nudge this along:
  • Review the PR (or recruit somebody with deep knowledge of Plug and RFC 7233 to do so)
  • Test the PR in your local environment and let us know if it works, or if not, how it fails
As a quick-n-dirty alternative, you could also try https://hex.pm/packages/plug_range, but please be aware that this module implements none of the content restrictions found in Plug.Static. It could easily be used to reveal files stored on your server that you might not want to make public. I would advise caution in using that module.

-Eric
Reply all
Reply to author
Forward
0 new messages