a year ago
Hi, i am using node js project, my project structure is projectfolder/src and projectfolder/uploads, when i use volumes in here i am using /home/node/app/uploads path but when i redeploy the code again image not getting,
please help me on this for volume path and if i redeploy image will not erase
17 Replies
a year ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • about 1 year ago
a year ago
please give the solution for above issue
a year ago
for node js project
a year ago
I'm sorry but that doesn't quite answer my question, what is your current volume mount point.
brody
I'm sorry but that doesn't quite answer my question, what is your current volume mount point.
a year ago
sorry for that, i am created volume like /uploads
I am using Node.js and MySQL for the back-end, and React.js for the front-end. Both apps are hosted on this platform, and the project is currently in the development stage.
The issue I'm facing is that when I upload images via the API, they upload successfully. However, the images are not displaying correctly. Sometimes, after deploying new code, these images get deleted.
for using i am define variable this path https://sthanickbackend-production.up.railway.app/images/
a year ago
Try mounting the volume to /app/uploads
brody
Try mounting the volume to /app/uploadshttps://docs.railway.com/guides/volumes#relative-paths
a year ago
Need to create below variables ?
RAILWAY_VOLUME_NAME: Name of the volume (e.g.foobar)RAILWAY_VOLUME_MOUNT_PATH: Mount path of the volume (e.g./foobar)
if i use the above variable names, mysql volume coming, how can i set for uploads (volume ) name
a year ago
can i use
const uploadDir = '/app/uploads'; like this is this correct ?
for retrieving image i use like this in node js
app.use("/images", express.static('/app/uploads'));
a year ago
> Need to create below variables ?
You do not need to define these variables on the service, they are automatically set by Railway at runtime.
> if i use the above variable names, mysql volume coming.
Sorry, but I'm not sure how MySQL comes into play here?
> how can i set for uploads (volume ) name.
Sorry, I do not know exactly what you are asking, please elaborate.
> app.use("/images", express.static('/app/uploads'));
Nope, use ./uploads in code.
---------
Please try mounting your volume to /app/uploads
Status changed to Solved brody • about 1 year ago
Status changed to Awaiting Railway Response simha18 • about 1 year ago
a year ago
Hi, i use the path like above /app/uploads and uploaded image from api but after redeploy image not coming same issue happens again, please resolve this, i follow the same thing what you mentioned above or please provide some same code Node js with multer
Status changed to Awaiting User Response Railway • about 1 year ago
brody
Are you using ./uploads in your code?
a year ago
/app/uploads i am using
Status changed to Awaiting Railway Response Railway • about 1 year ago
Status changed to Awaiting User Response Railway • about 1 year ago
brody
Please try using ./uploads in code.
a year ago
// Image upload
const storage = multer.diskStorage({
destination: (req, file, cb) => {
const uploadDir = './uploads';
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
}
cb(null, uploadDir);
},
filename: (req, file, cb) => {
const randomString = Math.random().toString(36).substring(2, 15);
cb(null, Date.now()+ '_' + randomString + path.extname(file.originalname));
}
});
// Image retrieving
app.use("/images", express.static('/uploads'));
i use like above both is that fine ?
Status changed to Awaiting Railway Response Railway • about 1 year ago
Status changed to Awaiting User Response Railway • about 1 year ago
a year ago
Hi i am using the same, but image not uploaded and not getting, please find the attachment
Attachments
Status changed to Awaiting Railway Response Railway • about 1 year ago
a year ago
Sorry, I don't see what the issue is -
https://sthanickbackend-production.up.railway.app/images/1738148405459_8pv600qfi75.png
Status changed to Awaiting User Response Railway • about 1 year ago
