I am trying to display png images on the fly in production
The problem is that I have an upload directory at priv/static/uploads and according to the user request I am creating an png image file on demand and copy it to the uploads directory
It is working fine in development, but in production it is not
I figured out that the problem is that the image don’t have compressed file and that is the problem
yes I know
The file name is xxx.png and if it is exists when I run MIX PHX.DIGEST it will be created again with the name xxx-{longid}.png
In this case, I can see it because it in the manifest file
There are a few misconceptions here. mix phx.digest has nothing to do with showing files. It just takes files where they are and creates a manifest file for them + copies of the files with a hash in the name for cache busting. It does not move any files.
at: "/uploads",
from: :scandoc,
Means the files are expected at Application.app_dir(:scandoc, "/uploads"), which for mix is ./uploads and not ./priv/static/uploads.
I created ./uploads and add the files to it
same result
phx.digest has something to do with it because whan I ran it before start my release, I am able to see the file. and that means that the directory is on ./priv/static/uploads
I have the same files in development and if I creating the file (they are created at ./priv/sattic/uploads) and run phx.digest (on development) and copy all the files over to the production machine I do see the files
Sorry for that: I mixed up from: {:scandoc, "/uploads"} with the settings you have. So your path within priv/static should be correct.
You can only do that with files created before your build the release. You still didn’t answer how you’re saving the file when you create it on demand in production.
if File.exists?("#{name}.png") || File.exists?("#{name}-0.png") do
{:ok, thumb_path}
else
result =
case System.cmd("convert", args, stderr_to_stdout: true) do
{_, 0} -> {:ok, thumb_path}
{reason, _} -> {:error, reason}
end
# :timer.sleep(300)
result
end
because it is an external command I have to path the full linux path
/home/…
so I am creating the png file in the correct place, but sometimes I can see the png and sometimes I am getting a wrong one.
When I look at the page info on the browser the file is mark as html/text and not image/png
The same file from the linux cli show that the file has a correct mime
I moved it to my local machine and I can see a good image file, so the file on the disk is ok