I can't see png files without phx.digest

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

here is my endpoint entry

 plug Plug.Static,
    at: "/uploads",
    from: :scandoc, ##"./uploads", #Application.get_env(:scandoc, :full_upload_path),
    gzip: false,
    only: ~w(png jpg pdf)

You can see my attempts to solve the problem :slight_smile:


This means you are only serving files from within the folders “png”, jpg" & “pdf” within your :from path.

1 Like

Can you show how you build the path for storing the file in?

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

The file type is not changed

what do you mean? Just created a directory with the name uploads under priv/static
The thing is how do I override the phx.digest step to display it

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.

I am converting from pdf to png

    if File.exists?("#{name}.png") || File.exists?("#{name}-0.png") do
      {:ok, thumb_path}
      result =
        case System.cmd("convert", args, stderr_to_stdout: true) do
          {_, 0} -> {:ok, thumb_path}
          {reason, _} -> {:error, reason}

      # :timer.sleep(300)

And thumb_path is build using Application.app_dir or :code.priv_dir? If not it’s likely you’re putting things in the wrong place in production.

1 Like

because it is an external command I have to path the full linux path
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