jkwchui

jkwchui

Where to put temporary files when deploying?

I have a simple LiveView app that

  1. write user input to a temporary markup file (content.typ),
  2. drops to System.cmd/2 to process this markup with a CLI (typst), and
  3. 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

Also Liked

LostKobrakai

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

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

Hermanverschooten

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement