Displaying/Accessing images uploaded to persistent disk

I have an express nodejs api that uploads images to my persistent disk. (Paid service)
I can verify that the file is uploaded to the service, both through shell and disk usage.

However, I don’t know how to access the files. How do I display the images that have been uploaded?

Example:
Images are uploaded to: /uploads/userfiles/uuid/awesome.jpg
But I can’t see that at: https://mycoolapp.onrender.com/uploads/userfiles/uuid/awesome.jpg

Since that upload directory is not relative to the code in my app… How do I access that?

Do I have to write a custom route in my api to write/read those uploaded folders/files under /uploads/userfiles/ ? Or is there a web.config route I update somewhere?

If so – How? (Documentation anywhere? What would I search for for reference? Routes to virtual directory?)

Hi,

How the files are served would be up to you.

A Render Disk mount path is just a folder on a disk, they’re nothing special from your web server’s point of view. They are not automatically available via a URL, as that’s down for your web server (in this case Express) to sort out.

In Express, you could maybe just use express.static: https://expressjs.com/en/starter/static-files.html

Or, create your own route in your code to serve the files from the disk mount path, if you want to do something special/custom with the assets.

Thanks -

I was referencing express.static before - but it 's not working.

Per docs:
app.use(‘/static’, express.static(‘public’))

and in their examples, the /static is recursive - meaning that all directories under that route accordingly.

But adding that to my codebase does not seem to make the necessary routes at all.

In my specific case neither of these work with the “mount path” of /bunny/userfiles

app.use(“/bunny”, express.static(“bunny”));

  • or -
    app.use(“/bunny/userfiles”, serveStatic(“/bunny/userfiles”));

which would try to deliver:
https://bunnyapi.onrender.com/bunny/userfiles/06DE52E0-B677-2F46-DAD166747DF93842/JR-Ewing.jpg

both result in the error: Route doesn’t exist!

I have not had to route to directories not directly accessible to the webservice before - so this is all very new.

Specific code implementation is beyond the scope of our support, as you’re the one who will know your app best.

But from the Express docs it seem the pattern is:

app.use('/optional/url/you/want', express.static('/filesystem/path'))

So if your Render disk mount path is /bunny/userfiles and you want them on a URL path starting /userfiles the line may be:

app.use('/userfiles', express.static('/bunny/userfiles'))

Which, if I’m reading the docs right (and the uploaded path you shared exists under /bunny/userfiles) should create the URL: https://bunnyapi.onrender.com/userfiles/06DE52E0-B677-2F46-DAD166747DF93842/JR-Ewing.jpg

Thanks.

Yes - I think that code “should work” - as the context appears correct to me as well. (That is the directory and URL… ) However, it does not work.

I will just have to keep banging on the code… when I find a fix, I will post it.

Got It!

Changed order of code - placed this Static Route before API Routes - AND - deleted duplicate directory under /public - which fixed this static route.

Thanks again!

Glad to hear you got it sorted.

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