Volume Path and Django Media Root

I have a new app that involves uploading images. I have tried all sorts of different combinations in fly.toml and my settings.py, but nothing has worked yet. Let’s pretend my app is named ‘fubar’. Here is what I am doing right now before my flyctl deploy:

# fly.toml

[[mounts]]
  source = "fubar_media"
  destination = "/data"
# settings.py

MEDIA_ROOT = BASE_DIR / 'data/media'
MEDIA_URL = '/media/'

Let me ask a few questions:

  1. There seem to be discrepancies between V1 and V2 with regard to the path. I am not altogether sure whether the [mounts] destination should be "/data", "/app/data", or "/fubar/data".

  2. Perhaps my MEDIA_ROOT should simply be '/data/media' and should exclude the BASE_DIR?


I used these values for my first attempt:

# fly.toml

[[mounts]]
  source = "fubar_media"
  destination = "/media"
# settings.py

MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'

Thank you for any help you can provide!

Hey @zip

Can you have a look at this? Add Volume Storage · Fly Docs

documentation suggests something like this

# fly.toml
[mounts]
source="myapp_data"
destination="/data"

where myapp_data is volume name
and /data is location where you want to mount the volume

1 Like

Hi @darkcheftar007,

Update: Thanks - Yes, I been setting the destination to the root, "/data", and my uploads are working and they persist. At this point my issue is Django itself, which is refusing to serve local media files. If I find a solution I will post it here.

Check this,

Hope it helps

The way I have been trying to do this is with Whitenoise, but it’s not working:

# settings.py

WHITENOISE_USE_FINDERS = True
WHITENOISE_AUTOREFRESH = True

STATICFILES_DIRS = [
    '/data/media',
]

Whitenoise is correctly serving my css, but not the media images uploaded by an admin.

Has anyone figured out how to do this? Sorry to resurrect a dead thread, but I am currently stuck on the same thing.

Hey @Opuffer,
Welcome to community.
Have you figured it out?

I am stuck on this same issue. I have successfully deployed my django project with DEBUG = False, and although static is being served successfully from a volume located at /data, the same cannot be said for media.

# fly.toml

[mounts]
  source="mydata"
  destination="/data"

# settings.py

if ENVIRONMENT == 'Development':
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
elif ENVIRONMENT == 'Production':
    MEDIA_ROOT = '/data/media'
MEDIA_URL = '/media/'

When media is added to a model via the Admin portal, I can see that the file is being added to the storage volume, but when I then go to a template which tries to render this media (e.g. a user profile photo), all I get is a broken image icon. Can somebody please tell me how to serve media from a fly volume?

Ultimately I believe Django prevents local files that have been uploaded like this from showing up for security reasons I believe. Django collect static needs ran in order to show static files and since it is never ran to collect the new images it can’t display them. Which is really unfortunate because I want to do the same thing. I don’t want to have to store images in some far off land just to display them, it’s dumb.

this thread solved this issue for me

Been a while, but I found a method that works for me.
Create a view that returns files from disk. Specifically I have a view/function that returns files from static/images/ and then I just pass the rest of the path/name into the function and it will return the image.