a year ago
Hi, I've only recently started learning web development and I'm very new to all this. I used this service after seeing it recommended on the Odin Project to host my first website.
I have a simple Node/Express blog website with a Postgres database for all the blog posts, with relative paths to the images stored inside them. Currently everything is on a single Github repo that the project is based off, and while it works the way it is and isn't that large so far, I figured I probably shouldn't host all the images on the repo going forward. I'm not quite sure how else would be the best way to go about it so I'm just looking to be pointed in the right direction.
I found the Filebrowser template on Railway but as far as I could tell I had to unmount the volume from the project whenever I wanted to upload something? Plus I couldn't figure out how to configure the path correctly. I might not even have the right idea here of how I'm meant to be using volumes. Or projects, or Railway.
9 Replies
a year ago
hey, I'm glad to hear you chose Railway for your web dev journey
you have the right idea, storing images in a repo is okay for design assets and stuff but if you're storing a lot of images that act as content for your website rather than design (like images on pinterest for example) then a volume is the way to go
The filebrowser template is a good way to upload files onto a volume if you're not going to change the files in the volume frequently, if you are changing them frequently then you might want to build the functionality of uploading images into the volume directly into your app
to give you an idea of how to do that, brody (a Railway employee) has a few example applications for file-uploads here:
Using Multer: https://github.com/brody192/multer-file-uploads
Using Busyboy: https://github.com/brody192/busboy-file-uploads
If you do change the images on your website somewhat frequently but not frequently enough to warrant making a whole file-upload process for it then you could try using Filebrowser as your file-storage, you can then fetch the image URLs from filebrowser and use them within your application, just make sure that fits within your use-case
a year ago
thank you!! i'll get started on making a way to upload posts directly from the website in that case. if all the images on the repo are currently stored in /public/img and all the blog posts reference that path, is it as simple as moving the images over to the volume, setting the mount path to presumably something including "/public/img" (i couldn't figure it out before) and then they'll show up fine?
a year ago
Exactly! Although you'd want to mount your volume on "/app/public/img" because your app is placed in the "/app" directory (assuming you're not using a Dockerfile with a custom root directory set)
Status changed to Solved unicodeveloper • 12 months ago
Status changed to Awaiting Railway Response owlhoods • 12 months ago
a year ago
hi, thanks for the help. i've added a page to handle uploading images to a selected path, but i'm having trouble getting them to persist across deployments. i uploaded a few to test it out and they showed up fine, so i disconnected the volume to use filebrowser to upload the rest, but there wasn't anything there. then when i reconnected the volume the images were gone there as well. in my app i'm using ${process.env.RAILWAY_VOLUME_MOUNT_PATH} as a write destination with Multer, but i also noticed that when i uploaded some larger video files the 'volume usage' in my volume's metrics weren't going up? do you know what i might be doing wrong?
a year ago
That's weird, so clearly the files aren't going into the volume.. 
is ${process.env.RAILWAY_VOLUME_MOUNT_PATH} the full write destination? or are you prefixing it at all?
Where's your volume mounted to?
a year ago
volume is mounted to /app/public/img, locally the variable is set to public/img which also works. full write location is
${process.env.RAILWAY_VOLUME_MOUNT_PATH}/${req.body.location}, i tried without the /${req.body.location} and that wouldn't write to the volume either
a year ago
interesting, can you jus try using /public/img then instead of process.env.RAILWAY_VOLUME_MOUNT_PATH, I know that seems counter intuitive but I'm curious if that'll solve anything
a year ago
hi, sorry for the late reply, just tried this with no change
10 months ago
stepped away from this for a while but trying to get it working again. i can use filebrowser to upload files, disconnect the volume then connect it again with the same mount point and they're gone. the volume usage metric doesn't change at all during this
EDIT: got it working somehow! just deleted the volume and added a new one. can't think of what else could've changed. oh well
