2

When uploading files, I am setting the upload_to to a function that creates a path doesn't exist, and Django is creating the extra folders (with permissions I don't like).

For example,

def photo_upload_path(instance, filename):  
    return os.path.join('photos', str(instance.id), filename)

however, the permissions of the folder are not what I would like. Should I create the folder and set the permissions? Or is there a setting for this?

I found a post for controlling permissions of uploaded files (django / file uploads permissions), but not created directories.

Thanks for any help!

Community
  • 1
  • 1
pyramation
  • 1,631
  • 4
  • 22
  • 35

2 Answers2

4

You could change the default directory permission in your settings file. This is available after Django 1.7, and is fully described in the Django documentation. Note that this will affect all directories created by Django, including staticfiles, so use with caution.

FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755

Change the example code to use the permission you desire. I didn't use your requested permission (0o777) in my example code in case someone copies without reading.

dbn
  • 13,144
  • 3
  • 60
  • 86
0

so I ended up finding out a solution for the permissions.

I was using apache, so I believe it was actually not 100% a django issue.

If I edit /etc/apache2/envvars and set add a line such as umask u=rwx,g=rwx,o=rwx, it sets the default permissions

pyramation
  • 1,631
  • 4
  • 22
  • 35