jkwchui
Where to put temporary files when deploying?
I have a simple LiveView app that
- write user input to a temporary markup file (
content.typ), - drops to
System.cmd/2to process this markup with a CLI (typst), and - deliver the output (
content.png) to the client
In dev, I specify the path for the temporary files as
Application.app_dir(:typeset, "priv/static/uploads/")
and this works on my machine™.
I then have this dockerized and deployed on Fly, copying the Typst CLI to /bin and verified the CLI works by ssh in.
However, the temp files are now written to a directory that does not exist.
** (File.Error) could not write to file "/app/_build/prod/lib/typeset/priv/static/uploads/content.typ"
What is the proper way of handling temporary files, to be processed with a CLI, when deploying?
Marked As Solved
LostKobrakai
Also Liked
LostKobrakai
Giving people access to all your system tmp files is not a good idea. You want to scope this to a nested folder for your application.
jkwchui
Thank you @LostKobrakai.
For future readers: you’d use System.tmp_dir/0 for the path. So if you want to write a content.png, it would go to
File.write!(
System.tmp_dir() <> "/content.png",
your_content_here
)
You can tell Phoenix to serve these as static files by adding a plug in MyAppWeb.Endpoint immediately after the only Plug.Static:
plug Plug.Static,
at: "/",
from: :my_app,
gzip: false,
only: MyAppWeb.static_paths()
# 👇 ADD THIS
plug Plug.Static,
at: System.tmp_dir(),
from: System.tmp_dir()
Hermanverschooten
Popular in Questions
Other popular 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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









