Image not found when deployed to Render

Hi,

First post; please be gentle… I am on a personal learning curve, just for the enjoyment factor; not planning to take over the world :). I built a web site using “web services” as a starting point. It’s all gone amazingly well including integration with GitHub which all works fine.

The problem I have is that my web site works fine when running locally, but when I deploy to Render, images are not displayed. Looking at the error returned by the client browser, it’s a “404” which I think means “Resource not found”.

I’ve done a whole load of Googling but not found a solution and so I’m posting here in the hope that someone might be able to help. I’m using Node and Express with EJS as the render engine. Nothing more right now.

My JS program does this on initialisation;

app.use(express.static(“public”))

Which is exactly what I think is suggested by this;

https://expressjs.com/en/starter/static-files.html

And I put my static content in directories below /public. Mostly this works fine and in fact I have the following directory structure on my local machine; In /public I have two directories and one file.
/css
/images
index.html

The index.html file is served as the application home page. My application finds files in the css directory but it won’t find files in the images directory.

I use the following to load an image;

image.src = “./images/BBLcourt.png”;

but I’ve also tried;

image.src = “/images/BBLcourt.png”;

Meanwhile the browser is looking here;

https://myAccountxxx.onrender.com/images/BBLcourt.png

Which is again just what the Express documentation proposes. Could the problem be that I’m using a .PNG file? Dunno.

Also… Obviously I’ve checked that the directory structure needed by /public/images is actualy in my repo; it is. My code does not do anything to build this directory structure; I’m just assuming that because it’s in the repo, Render will deploy it, just like it has been shown to do with the /css and index.html directory/files.

There might be a problem with Node (or Express) versions. I’m using; Node V18.13.0 (I don’t know how to find express version). I note that my Render build uses V20.15.1. Could that be the problem?

Any pointers would be appreciated, thanks for your attention.

Dave

Hi there,

Note that on Render, your service runs on Linux, which uses a case-sensitive filesystem. You need to make sure your file names and directories match the exact case of what has been pushed to GitHub. In this case, you will find the image name is bblCourt.png, so https://myAccountxxx.onrender.com/images/bblCourt.png works.

Regards,

Keith
Render Support, UTC+10 :australia:

Morning (well it is here) Keith,
Thanks for taking a look at this issue. I’m ashamed to say that you’re right; my bad.
Kind regards, Dave

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.