Upload media files for legacy Django site
zemogle
HOBBYOP

a year ago

I am moving a site from a different hosting solution. I've been able to port over the DB, the static files (CSS etc) are happily served via WhiteNoise. How do I upload all of the user uploaded files, i.e. the contents of the /media/ directory?

Solved

7 Replies

zemogle
HOBBYOP

a year ago

I've tried using the Filebrowser template. I followed the instructions i.e.:

1. Deploy filebrowser in your project
2. remove current deployment from your project
3. Disconnect volume from Django service
4. Disconnect volume from filebrowser

  1. Connect Django volume to Filebrowser

I can see a mount point called /media which matched the name I gave the mount point when it was linked in the Django service. But this did not contain the files I had uploaded (as a test) on my site. I thought this might be some error, so I uploaded some of the old files into the media directory.

Reversed all the above connections so Django was connected to the right volume again but I can't see any of the files I uploaded via Filebrowser.

I'm totally confused by this. Help would be greatly appreciated +1 emoji


a year ago

I think you want USE_VOLUME_ROOT set to 1

https://railway.com/template/Nan7Bs


zemogle
HOBBYOP

a year ago

Thanks! I did use that setting, which was how I could see the whole volume, including /media but the uploads weren't there. I'm wondering if I can check the files while the container is running.


zemogle
HOBBYOP

a year ago

I've been going crazy with this for the last week. I can upload my files into a volume attached to the Django service but I can't view them from the django app (i.e. the URL in the Django admin for the FileField gives a 404). I've checked they are being uploaded correctly into the volume (but connecting the volume to filebrowser temporarily) and they are. but they are not being served by the Django app.

I've set up with MEDIA_ROOT and MEDIA_URL exactly the same as the example Django templates. Normally I would check that NGinx was setup correctly or that my AWS credentials were correct but obviously volumes work differently.

There is something subtle that I'm just missing. It's going to be a killer for me using Railway if I can't get this worked out. Any help would be appreciated.


a year ago

I think you think that volumes come with their own file server?

If so, they don't it's just disk storage, your code needs to serve the files upon request, you are likely missing that part of your code, see here for an example -

https://github.com/railwayapp-templates/django-volume/blob/main/mysite/urls.py#L25


zemogle
HOBBYOP

a year ago

Ah ok! That was the missing piece. Thanks!

I think I'll need to see if this impacts performance. If it does then I will just connect an S3 bucket.


a year ago

Yes Django themselves recommends this is only used for development, but the files are still being served by Gunicorn not a development server, so unless you have a massive amount of traffic the performance impacts would be negligible at best.

But happy I was able to help in the end!


Status changed to Solved brody about 1 year ago


Loading...