Getting and downloading files from a Volume in Django
Hi
I have a Django app deployed on Railway with a volume attached '/storage' which contains some sub-directories (invoices, news_images, driver_images) which each contain images or pdf's.
I have a 'file viewer' page which displays these files to be downloaded.
I'm ensuring the directory, and the funny thing is the files are clearly there as the path was found, however images don't load and pdf's aren't accessible.
I have removed trailing slashes as Django adds slashes to urls by default which I thought could be the issue
However this hasn't solved it.
This works in the local environment, just not in the railway environment.
Is there some strange quirk about the volumes in Railway? Not having FTP or SSH is the
reason we need this, however any workaround will do.
The page renders with the image filenames and pdf's listed, however they lead to 404s
When inspecting in the F12 menu, the URI's for the images are what should be correct, however also lead to 404s.
Thanks
3 Replies
your volume is mounted to
/storage
but it sounds like you are trying to save and load files into a storage
folder that is relative to your project folder.
when you mount a volume to your service it is mounted at the root of the container, not at the root of your project, you may instead want to mount the volume to /app/storage
as /app
is where your project is copied intoHi Brody thanks for your help. I have changed the mount path to /app/storage/, changed the media root to correspond with that. Still with the same issue of the files being discoverable, but not downloadable. Thanks
Edit : For more context, it works in the testing environment, but not the production environment. Same code, same setup with the volume etc.
have a look at how this template handles serving the files https://github.com/vfehring/django-volumes
specifically the urls.py file