Railway volumes in Django not working as expected
Hello! I added a Volume to my Django project on Railway for persistent storage of PDF-Generated files. I set the mount path to /media. From what I read, there will be a media folder in the base directory (or maybe I need to create one if it does not exist) where the data will be persisted. However when I deploy changes all the files are lost. When I try to access a file using os.path.join('media', 'hello.pdf') I get a file does not exist error. I don't know if I am missing something.
Solution:Jump to solution
your paths are incorrect, please give the guide a read https://docs.railway.app/guides/volumes
7 Replies
Project ID:
98888b3e-8302-4a34-a31a-6ba9963dccee
Project id is: 98888b3e-8302-4a34-a31a-6ba9963dccee
Solution
your paths are incorrect, please give the guide a read https://docs.railway.app/guides/volumes
Alright. I'll read the guid and I'll be right back
Thank you very much. After reading the guid carefully, I realized you were right about paths being incorrect. Indeed, I thought the media directory would be created inside my Django project directory, but it was one level up my directory, so I had to use the ../media relative path to access the volume storage directory. I tried to deploy some changes and the files are still accessible. Thank you
you can use the
media
path like you where, but instead set the mount to /app/media
this is what i had hoped you would take away from the docs pageOk. I'll try that, too. Thanks
It works too.
awsome