Object storage service
whoever read this I hope you are having great time 🌹 , I need help with understanding volumes.
Does railway have a solution for Object storage, i mean something alternative to "Amazon S3" or "DigitalOcean Spaces". I would appreciate if one could explain the difference between such services and "Railway Volumes". I'm not sure I understood what volumes are and how to utilize them correctly.
58 Replies
Project ID:
N/A
N/A
you can think of volumes like a mounted drive on your computer, because that's pretty much exactly what they are. a persistent storage volume mounted to your chosen mount point that provides filesystem storage.
and railway has a minio template which uses the volumes for the underlying storage and exposes an S3 compatible api
https://railway.app/template/SMKOEA
But how can i access that drive (volume) from my project files and during development?
the same way you would access any files on disk, if you mount the volume to
/data
for example, then you save a file like /data/text.txt
and then read it back from that pathI'll test it out ok 👍
for sure, if you run into troubles you can come ask
Many thanks man 🌹
my pleasure
I'm currently testing it with a DRF (Django Rest Framework) app to upload files. Locally, everything works perfectly fine, but I encountered a problem when I deployed it. I am using Dockerfile.
The problem specifically arises when I try to access the uploaded files on Railway.app. On my localhost, when I click on the file path, the file downloads without any issues. However, on Railway.app, it gives me a 'Page Not Found' response instead of the file.
To provide some context, in my Dockerfile, I have set the working directory, and the files are saved in a folder called 'media' within the project root.
The API is receiving (post request) with no issues, and because the file is stored in the project root; it can retrieves data such as file name and file size through GET request. These attributes are not stored in the database. Instead, they are dynamically read from the saved file's attributes.
On my localhost
When deployed
He only difference would be in the file path
are you saving the files into the volume when on railway? it doesnt seem like you are doing that?
I'll be honest with you i can't confirm if i am doing so or not. In fact that's what i would like to know.
Normally that destination of the uploaded files should be
"BASE_DIR/media"
your media root should only be the volume mount point
at least when running on railway
If the working dir is ./code
Then what would be the path for railway volume?
./code/media?
Or ./media ?
you mounted the volume to
/media
so the volumes path would be /media
So i should think of the project now as
- media
- code
- - app
. . .
?
where does
app
come from(App is what ever code that is inside the ./code)
Which is in this case:
correct
Ok, i kept asking to make sure i understood you correctly. Thanks for being patient ❤️
I'll test it 👍
-------------------------------------------------
i Just had tried working it as you mentioned,
changed the root of the mounted volume but still i cant reach the file for some reason. Pardon me for the late try, i couldn't play with it the last 2 days, if you noticed i was even sending screenshots from my phone and github mobile app.
the updated root for the mount
the structure is as:
- code
- - Dockerfile
- - media
- - core
- - - settings.py
dockerfile:
inside settings.py i set the following:
this is a classic case of not doing what I said lol
^
Base_dir points to ./code
Here it is ./code/media
I know, you don't want that, the volume is mounted to the root on the container, not inside of the code folder
^
No i changed that
Look
put it back to /media
I tried that too
It didn't work
yes then remove the base dir
I did yup
okay and 404 right?
Yup
okay so then you have to find out a way to tell django to serve files from the media folder
currently it expects a separate file server to do that for it
I thing it has to do with django media and serving system and not railway volumes
Yup
I wished i didn't understood that currecrly and there is an easy way around it such as railway volumes
show me your urls.py file please
But i guess i have to do some configuration to the apache server or something to make this work
1 min
yes this is type of thing django does expect of you, but that is too complex for a little site
django wants you to run it behind a proxy like nginx, where nginx will serve media files from the media volume, and proxy all remaining requests to django
Yup thats what i found searching in the past 3 days
But since i never did that before i tried looking for another away. Anyways i guess sooner or later i gotta learn how to integrate nginx with the stack 🤷♂️
I'd personally use caddy
but there has to be a way to get django to serve files from the volume too, may not be the best practice but I'm sure it can be done
Honestly speaking i am still new to all this and there is already so many things to figure out like JWT auth between django and nuxt, learn nuxt itself, and then try doing something asynchronously
I've never done jwt auth
I've always just used uuid's in cookies
The auth thing itself i am new to it 😂, just used to django-allauth without solid understanding, but since i want to move into building apis i thought of delving deeper into auth as well
With apis and separated front-end, seriously the possibilities of one can make is endless 🔥. But the amount of topics to learn is also overwhelming too 😂
slap an API key on your requests and you're good
It is always refreshing talking to you man, thanks for your great efforts into this community.
Btw what confuse me the most, is that the file is indeed uploaded and is there somehow, somewhere. Because the size, file name are dynamically read from file attr and not stored in the data base
I'll see what I can whip up at a later date, so far this makes two people who have asked how to do this
using a fileserver + proxy should also eliminate the need for whitenoise
Yup, from my research it seem like if one used a cdn it will cover the static file and media files
well yeah but then you aren't using volumes at all
Yeah that will be an external service like digitalocean spaces or AWS S3.
I don't know if I'd use object storage as a cdn