I am having an issue that I could not access file under phoenix’s priv folder on Heroku.
In the code i am using
Path.join(:code.priv_dir(:jagatsingh_line_bot), "replies/welcome.yaml") to access the file path. In the development it working find but in the heroku I am getting the below error -
could not read file "/tmp/build_8f88e6da2cc083a18821ba5912f46548/_build/prod/lib/jagatsingh_line_bot/priv/replies/[welcome.yaml]" no such file or directory
I have also check that I am not ignoring the /priv/repo folder from version control.
If anybody have faced the similar issue or have solved this issue please share your solution.
Are you running
mix phx.digest at some point in your deployment? My knowledge is relatively limited in this matter, but I believe that may be needed to work with priv/static files. Not 100% sure, but hopefully this is a good breadcrumb to follow! Good luck!
How does your folder layout look like and does it work locally?
@NobbZ my project folders are in standard phoenix folder layout.
I created another folder called ‘replies’ under ‘priv’. just to save my .yaml files there.
@cdfuller I don’t think it is because of digest task, since it only take care of files under
priv/static by default.
I also remote access onto heroku app, to see if the file is already under the _build’s priv also. The result is that the file is already there.
From the above image and the error from the log, I am seeing that the dyno for actual execution and dyno for console is actually different, since the directories prefix of the project folder, are different.
Why are there brackets around the path in the error? That seems odd to me:
I think that was my mistake of copying, Actually there is no
 brackets there.
Are you running this at build time, for instance by storing it in a module attribute or calling it in a plug’s init function?
This code is written in a module definition below as in below image -
That‘s probably the problem. You‘re storing the path at compile time in the module attribute instead of getting it at runtime. I‘m not sure if paths change between compile time and runtime on heroku, but I‘d rather expect them to change instead of the opposit.
Thank you @LostKobrakai for pointing out the issue here.
Yes, setting path at compile time is the cause of issue here, I switch from
@welcome_reply Path.join(:code.priv_dir(:jagatsingh_line_bot), "replies/welcome.yaml")
defp welcome_reply do
to resolve my issue here.