Where can you store Media Files?

I'm using Django and have added a blog module to it where users can upload their own images. I was wondering whether it is possible to store those images on Railway? Thanks!
Hello, you'll want to use a volume to store persistent data. https://docs.railway.app/reference/volumes
Hi, thanks for letting me know. I added a volume to my web app but wasn't able to get it to work.
It's linked to the project but nothing seems to get added to it despite the URLs pointing to /media/ as well
please reference this template
I took a look at the template and implemented its suggestions which seemed to be changing the media root to MEDIA_ROOT = os.environ["RAILWAY_VOLUME_MOUNT_PATH"] and then the volume’s Mount Path to /app/media.

After doing that, I can now see that the files are uploading somewhere as the disk usage is increasing. The problem is the files are still not showing up on Wagtail Admin (the django blog app) and the image links are not working.

Any suggestions on what to try next? I’m pretty much stumped.
Are the links pointing to the correct location? Maybe you also have to configure wagtail to work with the new path.
Do you know if there's any way to access the volume manually through the command line?
There is not that I know of, but you could probably use this. https://railway.app/template/Nan7Bs There is another one for downloading.
By default, the storage location is set to the storage subdirectory in the root of the volume, but by setting a service variable USE_VOLUME_ROOT to 1 you can opt to use the root of the volume as the storage location instead
I finally resolved this by reviewing all the code in the django-volumes example. The guy who wrote this wasn't really clear on what changes to make so it took ages to figure out. Also, he seems to be using an unrecommended workaround which isn't meant for production.

It was this line that ultimately got it working: urlpatterns += [ re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]

This is where in the documentation it clearly states that this is for local development only: https://docs.djangoproject.com/en/4.2/ref/views/#django.views.static.serve

Is it better to just split user-uploaded files off and serve them from an S3 bucket?
yes that isn't recommended for production but as that template is a starter project it is perfectly adequate for its intended usecase, and as your project grows and you learn more about web development you can implement a static file server with caddy or nginx yourself

Looking for more? Join the community!

Recommended Posts
Easy (?) shared variables questionThe environment contains the excellent Payload CMS template, attendant Mongo DB, and a Next.js frontPlan update issueIm having a issue with plan update. It just shows: Problem processing payment method and I triple cCan't create an account: Device requesting login is not supported. Please try again from a secure coTrying to create a new Railway Account, but getting this error: ```Device requesting login is not saccess to resource inside replicahi, when we setup an instance to have 2 replicas, how do we get the resource related to 1 of the reCommunicate between services with private networkProject ID: 3f51dcb4-6905-4a13-be75-4c6063e4324a I am trying to set up Railway to communicate betweWeb Server Not WorkingI just started a small simple web server. I generated a custom domain for now, and when trying to achttp:// to urlI am using a Django REST framework. When I query the URL at I can get a response, but aOpenSearch deploymentHi everyone. I require assistance with deploying an instance of OpenSearch since I get an error durUnable to connect with private networkHey guys, I'm a bit unsure on how to use the internal network. I have a .net api that has a privaterclone on railway to transfer data from one cloud to an other.Hello, I'm creating an app the requires to transfer data from one cloud storage (like onedrive to aBun 1.0 on railwayI am spinning up a simple bun app with 1 file in it. But for some reason all of my builds are failinSocket cannot be archivedWhen building the railway project I get a message saying that: /Users/x/Library/Application SupportBUN 1.0 + AstroHas anyone tried to deploy a Bun app yet? I am getting this error. ERROR: failed to solve: processDjango Railway admin consoleHi! I've had a really good time using Railway thus far, sea-change from setting up an EC2 instance Trouble sending emails via SMTPprojectId: `bb66f5c0-53f9-4e9f-b11f-5965f5d6ec74` serviceId: `b3029692-b78a-4487-bcb0-44e001afecb8` Cannot have a TCP proxy and a domainWhen trying to create a service with a proxy, I'm getting this error. Can I not have a TCP proxy serChange region for Postgres DatabaseHey ! Congratulations for the launch of deployment region ! Now, how can I migrate my db to another Connection Pooling or PgBouncer for Postgres Instances?Hello! Anyone know if the Railway Postgres instance has any sort of connection pooling or pgBouncer?webhook to rebuild serviceHi I have one project: Mongo, PayloadCMS + storage, Nextjs I want to trigger nextjs rebuild after aI paid 40 dollars in subscription fees but its still dont pay my debt for credits.