Setting a custom media folder: need to change MEDIA_URL?

Issue #527 resolved
Vincent Leduc created an issue

Hi Randle,

I wanted to set a custom media folder for uploads as some files under media/ are commited to repo, and I wanted the media folder to be a symbolic link to a mounted remote file system, so as not to keep uploads directly on the QATrack+ server.

Once I created my symbolic link mymedia, first thing I tried was to set in local_settings.py:

import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(file))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "mymedia")

However, I could not access existing uploads (NOT FOUND error). I found that, on top of the previous modification, I needed to set MEDIA_URL in local_settings.py to the same value:

MEDIA_URL = '/mymedia/'

Is this expected? I would have expected these two settings to be independent, i.e. that the URL to access uploads did not depend on the name of the media folder.

Comments (4)

  1. Randle Taylor

    Hi Vincent,

    I have not tried this but you’re right, I would expect the URL to be independent of the file paths. Are you using Apache or IIS or …? Did you adjust your server configuration (e.g. your Apache conf file) to point /media/ at your new media location?

  2. Vincent Leduc reporter

    We’re using Apache, and I didn’t change anything in the Apache config.

    But you’re correct, I now have in local_settings.py

    import os
    PROJECT_ROOT = os.path.abspath(os.path.dirname(file))
    MEDIA_ROOT = os.path.join(PROJECT_ROOT, "mymedia")
    

    with MEDIA _URL left at the default value specified in settings.py

    In the Apache site config, I changed:

    alias /media /opt/qatrackplus/qatrack/media
    <Directory /opt/qatrackplus/qatrack/media>
    Require all granted
    </Directory>
    

    to

    alias /media /opt/qatrackplus/qatrack/mymedia
    <Directory /opt/qatrackplus/qatrack/mymedia>
    Require all granted
    </Directory>
    

    and now I can access my attached files under the /media URL. That was the missing step.

    Thanks!

  3. Log in to comment