Hi, before showing a image in my LiveView page, I want to check if this image exist or not
for this reason, I used File.exists?() and File.read, Although the image is in the preset direction but it shows me true or false randomly
this behavior destroys my conditions
if @form.value != nil and file_exist(@form.value) do
and:
def file_exist(file) do
Path.join(["apps/mishka_html/priv/static/", file])
|> File.exists?()
end
By “address” do you mean the absolute path or the relative one? And again, using :code.priv_dir/1 or Application.app_dir/2 will be much more reliable in general.
Using relative pathes will break as soon as you start the application from a different location than its src root.
Be very careful with passing form data to filesystem lookups. You don’t want someone to be able to pass “…/…/config/prod.exs” as a form input and have that show your production configuration and potentially secret tokens.