smolcatgirl
Hi,
I want to serve or stream video files in the phoenix web ui of my software. I store video filenames and file sources in my database. The source table have columns called id and location. When a user visits /video/1/test.mkv the video file called test.mkv from the source with the id of 1 should start playing. Not all video files live in the same source and the sources could be anywhere on filesystem, but not inside the the priv/static directory. Those videos files can be placed in this sources at any time after deployment and if a requested file exists in the given source it should be played in the browser. Otherwise 404 error should be sent along with a error message.
What do you think? What would be the best way to do this? Please ask if something is unclear!
Thanks for your time!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
kokolegorille
It should be the task of plug static to serve those files, but if You don’t want to put them in priv/static, You might serve them with a controller.
You can use send_file, or send_download.
Or You can have a template with video tag, to render those files.
smolcatgirl
The problem with the static plug is that plug static serves files that was compiled with the software. I need to start playing the files that was added after the software was deployed. The files should start playing directly and load more of the video as the user continues to play it. Videos are usually bigger than pictures in file size and if the internet connection from the browser to the server was slow I wouldnt want fully load the file in the browser before playing it. I am not fully sure how send_file does this but I will look into it.
Thanks!
kokolegorille
No, I don’t think so… You can configure plug static to accept wildcards, or directories.
smolcatgirl
Then what if I have one source in /mnt/video with source id and another in /mnt/video2 with source id 2? I need to serve / stream them as with the path as I said earlier. Sure I can use Plug Static for serving files outside of priv/static. But not like this. Also isnt it a bit weird to use to use a plug called static to serve content that gets added during runtime?
kokolegorille
Static files should be in priv/static. If You want to put the files anywhere, then use a controller to serve those files.
Parameters passed to controllers should allow file selection, them just serve them…
Something like /videos/:id/:filename
By the way plug static serve this by default, and your OP title is … static video file.
Anything put in css, or images etc. will be served. In addition, those files are not compiled.
smolcatgirl
What do you mean by “just serve them”? Using send_file?
Aha well what I meant by “static” was that it is a non changing video file, I is not a live stream or so. The files do not belong in priv/static because they are added duing runtime after deployment. I am changing my title to remove the word “static”.
kokolegorille
It’s in your your title… How would I serve…
smolcatgirl
Yes, and that is my question. How would play the video in the browser? I am unsure how to send it to the browser.
kokolegorille
You need a controller that serve those file with a send_file.
Then You can use thoses path as the src of a video tag.
smolcatgirl
Would this start playing the file and load more when if the user continue to watch?