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
No description
25 Replies
Percy
Percy14mo ago
Project ID: N/A
Akmal Dira
Akmal Dira14mo ago
help
root
root14mo ago
What server framework are you using?
Akmal Dira
Akmal Dira14mo ago
next js
ThallesComH
ThallesComH14mo ago
railway disk is ephemeral, did you add a volume?
Akmal Dira
Akmal Dira14mo ago
sure "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" } ],
Akmal Dira
Akmal Dira14mo ago
No description
Akmal Dira
Akmal Dira14mo ago
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),
buffer
);
await fs.writeFile(
path.join(process.cwd(), "public/uploads/" + filename),
buffer
);
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,
}));
const files = await fs.readdir(path.join(process.cwd(), "public/uploads"));
const result = files.map((file) => ({
src: "../../uploads/" + file,
name: file,
}));
ThallesComH
ThallesComH14mo ago
you've to save the files on where your disk is mounted, make sure you're doing that
Brody
Brody14mo ago
try to mount the volume to /app/public/uploads
Akmal Dira
Akmal Dira14mo ago
btw i mount volume /public, not /app/public it's the problem?
Brody
Brody14mo ago
try to mount the volume to the mount point I just provided
Akmal Dira
Akmal Dira14mo ago
can we see container file system on railway? maybe it store on wrong path
Brody
Brody14mo ago
your app can, but railway provides no ssh or ftp access try the mount point I provided please
Akmal Dira
Akmal Dira14mo ago
ok i'll try thanks @Brody problem still same, i've chage /public/uploads to /public, and create volume on /public, but same
Brody
Brody14mo ago
have you tried the exact mount point I gave you?
Akmal Dira
Akmal Dira14mo ago
yes but all public file not found
Akmal Dira
Akmal Dira14mo ago
so i change locate file upload to /public and volume on /public but same problem
No description
Akmal Dira
Akmal Dira14mo ago
all public file there, but when i upload new public file it'll 404
Brody
Brody14mo ago
it just seems like you are getting your paths all wrong, take a step back and think all this over
Akmal Dira
Akmal Dira14mo ago
solved with creating endpoint to return image next js /public path for static file only
Brody
Brody14mo ago
awesome, glad you solved it!
Akmal Dira
Akmal Dira14mo ago
thanks
ThallesComH
ThallesComH14mo ago
watch out, your code might be vulnerable if you're accepting path from the user and concatening it somewhere. https://owasp.org/www-community/attacks/Path_Traversal
Want results from more Discord servers?
Add your server