Skip to content

Set location for meda files on webserver  #108

@mikemhenry

Description

@mikemhenry

Trace back here:

Details
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
/tmp/ipykernel_31131/1487240485.py in <module>
     12     )
     13 
---> 14     value_object_csv = models.FileValue.from_string(
     15                 "molWeight_data.csv", challenge=challenge
     16     )

/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/core/models.py in from_string(cls, filepath, challenge, evaluation)
    555         with open(filepath, "rb") as fp:
    556             instance.value.save(filename, File(fp))
--> 557         filecache.preserve_local_copy(instance.value, filepath)
    558         return instance

/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/core/filecache.py in preserve_local_copy(field_file, filepath)
     43     at filepath into the local cache path.
     44     """
---> 45     local_path = _local_cache_path(field_file)
     46     if not os.path.exists(local_path):
     47         logger.debug("Copying local file %s into %s", filepath, local_path)

/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/core/filecache.py in _local_cache_path(field_file)
     16 def _local_cache_path(field_file):
     17     local_path = os.path.join(settings.MEDIA_ROOT, field_file.name)
---> 18     os.makedirs(os.path.dirname(local_path), exist_ok=True)
     19     return local_path
     20 

/usr/lib64/python3.8/os.py in makedirs(name, mode, exist_ok)
    211     if head and tail and not path.exists(head):
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:
    215             # Defeats race condition when another thread created the path

/usr/lib64/python3.8/os.py in makedirs(name, mode, exist_ok)
    211     if head and tail and not path.exists(head):
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:
    215             # Defeats race condition when another thread created the path

/usr/lib64/python3.8/os.py in makedirs(name, mode, exist_ok)
    211     if head and tail and not path.exists(head):
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:
    215             # Defeats race condition when another thread created the path

/usr/lib64/python3.8/os.py in makedirs(name, mode, exist_ok)
    221             return
    222     try:
--> 223         mkdir(name, mode)
    224     except OSError:
    225         # Cannot rely on checking for EEXIST, since the operating system

PermissionError: [Errno 13] Permission denied: '/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/media'

tl;dr need to

  1. Decide if we need the media file to be persistent
  2. Make sure we have the permissions correct ie
sudo mkdir /var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/media
sudo chmod g+s /var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/media
sudo chown webapp:webapp /var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/media

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions