save file on file system not found

i've create api to save file to public files

after i upload new file on railway host, 404 where i acess it,
but if i upload on local host and deploy app to railway, it's work

anyone can help me
What server framework are you using?
next js
railway disk is ephemeral, did you add a volume?
"result": [
"src": "../../uploads/1695115440009What-is-Generative-AI-what-are-Foundation-Models-and-why-do-they-matter-scaled.webp",
"name": "1695115440009What-is-Generative-AI-what-are-Foundation-Models-and-why-do-they-matter-scaled.webp"
"src": "../../uploads/1695137501651Pittsburgh_Pirates-Logo-PNG8.png",
"name": "1695137501651Pittsburgh_Pirates-Logo-PNG8.png"
right side is image where i upload on railway host
left side is image where i deploy it
i think it's because i use process.cwd() to find root of my app?
await fs.writeFile(
      path.join(process.cwd(), "public/uploads/" + filename),

but i get this result from
 const files = await fs.readdir(path.join(process.cwd(), "public/uploads"));
    const result = files.map((file) => ({
      src: "../../uploads/" + file,
      name: file,
you've to save the files on where your disk is mounted, make sure you're doing that
try to mount the volume to /app/public/uploads
btw i mount volume /public, not /app/public
it's the problem?
try to mount the volume to the mount point I just provided
can we see container file system on railway?
maybe it store on wrong path
your app can, but railway provides no ssh or ftp access
try the mount point I provided please
ok i'll try
thanks @Brody
problem still same, i've chage /public/uploads to /public, and create volume on /public, but same
have you tried the exact mount point I gave you?
but all public file not found
so i change locate file upload to /public and volume on /public
but same problem
all public file there, but when i upload new public file it'll 404
it just seems like you are getting your paths all wrong, take a step back and think all this over
solved with creating endpoint to return image

next js /public path for static file only
awesome, glad you solved it!
watch out, your code might be vulnerable if you're accepting path from the user and concatening it somewhere.

Looking for more? Join the community!

Recommended Posts
Can I create an environment from a secondary branch of a GitHub repository?Hello, I have a Node.js web app on Railway, and I'm looking for a way to create a second instance fServer becomes unresponsiveCan someone please help me figure out what occurred Saturday? Our production site was not accessibleProject with cron job aways skippedWhy my project nevers run with cronMaximum of 4 volumes per project?Heya 🌞 I have several services and would need to attach another volume to one of these but it get aAny way to skip redeployment if github ci is skipped?Here's what I see on dashboard, railway is granted all accesses in my org on github. On github I caBuild Error after RedeployRecently, I've been facing a weird error whenever I redeploy my railway instance from the dashboard.Restarting database not working.My postgres database wont restart. All data is not modifiy after restaring it.Adding support for python with isolated-vm npm packageHello, I am using a project that requires the isolated-vm npm package (https://www.npmjs.com/packageListmonk; Static FilesNot sure why my post was deleted, but here it is again: Hello, I've deployed Listmonk on Railway, ConcurrencyWill concurrent requests to a single endpoint work? And where would the logs appear for each individProblem with Flask-Caching/ RedisI'm trying to setup a simple caching mecanism to my Plotly Dash (Flask) application deployed to railWorker Killed IssueI'm getting the attached error when I try to request my app from a React frontend, whereas I wasn't Need help with deploymentSubject: Seeking Guidance on Loading Environment Variables in Railway for My Go API Deployment Hi ebun: command not foundHello, I'm trying to migrate my project to bun to make TS easier, and I'm when deploying, the logs Metrics on Number of Web RequestsI just deployed a web API and would like to keep track of the number of requests made to the API. DoIs there a timeout on my api functions when deploying a nextjs app?I coudnt find anything about this on google or the docs, Thanks for helpingI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moError comunicate with internal servicecsI'm trying to make a post on a route that is in an internal service on railway = api-ecompleto.railwUnchanged repo fails to deploy on env var change.I had this exact setup running last night, and this morning when I changed an environment variable i