Commit b9f13abe authored by Elizabeth Myers's avatar Elizabeth Myers 💬
Browse files

Fix media upload

parent cfa82a94
......@@ -127,7 +127,10 @@ class FileUploader(ABC):
class MediaFileUploader(FileUploader):
@staticmethod
def url_path(self, filename):
return f'media/{filename}'
@property
def storage_path(self):
return Path(conf.media_storage_path, 'media')
......@@ -163,7 +166,7 @@ class MediaFileUploader(FileUploader):
raise web.HTTPBadRequest(text='{"reason": "Malformed file"}',
content_type='application/json')
return dest_filename
return self.url_path(dest_filename)
@property
def max_file_size(self):
......@@ -198,7 +201,10 @@ class MediaFileUploader(FileUploader):
class AvatarFileUploader(MediaFileUploader):
@staticmethod
def url_path(self, filename):
return f'avatar/{filename}'
@property
def storage_path(self):
return Path(conf.media_storage_path, 'avatar')
......@@ -292,7 +298,7 @@ async def avatar_delete_handler(request):
return web.json_response({'reason': 'Bad file path'},
status=400)
file_path = Path(conf.media_storage_path, filename)
file_path = Path(self.storage_path, filename)
if file_path.is_file():
file_path.unlink()
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment