Hello, I am trying to load a file at runtime that errors out as could not read file "my_app/priv/private.pem": no such file or directory
the first time. However, if I refresh the page, it works perfectly fine. I assume this is because it did not have a chance to load the first time around. What can I do to make sure it works perfectly the first time around?
Can you share some code how you are accessing the file?
1 Like
You will need to use something like Path.join(:code.priv_dir(:my_app), "private.pem")
to get the actual path to the priv
dir in a compiled app/release
3 Likes
Application.app_dir(:my_app, "priv/private.pem")
does the same with a tad less complexity.
5 Likes
Thanks this works locally in dev, and in prod as well. I had to read a PDF to send as an email attachment.
|> attachment(
Swoosh.Attachment.new(
{:data,
File.read!(
Application.app_dir(:my_app, "priv/static/planners/#{dominant_personality}.pdf")
)},
filename: "#{dominant_personality}.pdf",
content_type: "application/pdf",
type: :attachment
)
)