Why can't we use absolute paths for FileField directories?

Django >= 3.2 does not allow absolute file paths for FileFields. Is there no way to disable this?

There are some scenarios where you might want to do this. For example, in our tests, we have to create objects with files, and we’d rather write these files to /tmp. In some use cases, e.g. chunked uploads, we create files which we end up deleting, and we may not necessarily want to store them in the /media/ directory. Finally, we are using a network file system mounted at e.g. /mnt/efs and might use that as a place to store files. These seem like reasonable use cases where the file paths need to be absolute, but now we get the SuspiciousFileOperation and I can’t seem to turn it off or ignore these.

Maybe I’m doing something blatantly wrong so any assistance with this would be much appreciated.

Thanks,
Keoni.

I think you can alter MEDIA_ROOT to make it an absolute path just by doing:

import os

MEDIA_ROOT = os.path.join(BASE_DIR, '/')

then expand on the path as you need to:

MEDIA_ROOT = os.path.join(BASE_DIR, '/tmp')

Maybe importing os is the old way of doing things, but it still works