Django / file uploads permissions

限于喜欢 提交于 2019-12-03 04:20:40
Van Gale

Try this in your settings.py if you use Python 2:

FILE_UPLOAD_PERMISSIONS = 0644

In Python 3 octal numbers must start with 0o so the line would be:

FILE_UPLOAD_PERMISSIONS = 0o644

For more details see the documentation.

Hope this is useful. The below method can be used. This has 2 other advantages other than resolving permission errors.

  • No issues with file permissions
  • More faster
  • The file is not copied to /tmp/ folder for files which are more than 2.5 MB (saving space as well).

with open(file_name, 'wb+') as temp_file:
    for chunk in up_file.chunks():
        temp_file.write(chunk)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!