Issue
When a user uploads a picture, my django code creates a directory (or folder if you want) with his name (picked up from the session user). This works in my local development environment but production does not grant that permission just like that. So, for savy system administrators out there here it goes:
This code is fine
MODEL
def user_directory_path(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
return 'user_{0}/{1}'.format(instance.user, filename)
images = ResizedImageField(size=[500, 300], upload_to=user_directory_path, blank=True, null=True)
VIEWS.py
for image in images:
Photos.objects.create(images=image, builtproperties_id=last_built_id, user=username)
So, this creates me a directory in this path:
media/user_peter
media/user_mary
etc
I thought that by doing this:
sudo chmod 775 media
It would allow the creation of subdirectories (user_peter, user_mary etc) but, apparently it does not as I got a "permission denied" .
What command would do that?
Thank you
I get this error when trying to let the system create a directory every time a different user wants to upload files to his directory.I manually hard-coded the user-language directory to see if it would let store files, but it does not. So, I need both things, the creation of directories on the fly and the storing of the images. Like I said, this works perfectly on my local computer development stage.
file "/home/boards/venv/lib/python3.10/site-packages/django/core/files/storage/filesystem.py", line 106, in _save
fd = os.open(full_path, self.OS_OPEN_FLAGS, 0o666)
PermissionError: [Errno 13] Permission denied: '/home/boards/alvar/media/user_language/commercial1.jpeg'
Solution
Sorry to disappoint the frustrated haters thumbing down questions the answer of which they don't know but here it is:
sudo chmod -R a+rwx /directory_I-want
the key is that if you need a directory being created, you need the x, that is, execution permissions.
and now I will take the opportunity to make a psychological analysis of many, (though not everyone), of those in stackoverflow: Rejected by women because of their anodyne look, lack of social skills, having spent most of their lives in dark rooms in the basement, they find no better way lo unleash their frustration but to thumb down whatever they see an opportunity to do. Bald, thick glasses, avoiding the mirrors, have developed a bitter character and that gets them even more rejections in real life, so they need to rush back to the basement to make it even as best they can. They think they are intellectually superior to those who are learning. In my case, I am a 61 year old pharmacist and master in economics, doing everything on my own. I am not a 22 year old lazy student of computer science.
Also, stackoverflow is a bad joke. I have seen (and recorded) absolutely simplistic questions that you can google anywhere getting up like hits of over one thousand and stackoverflow describes that as "a well thought ,meditated and profoundly researched question) and that will get them thousands of points, not to mention those who happen to be the first ones to answer that, another load of thousands of points. So long buddies, I solved it myself, going for a walk now :)
Answered By - Alvar Answer Checked By - Gilberto Lyons (WPSolving Admin)