mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
Merge pull request #2039 from haiwen/avatar_handle_error
[avatar] Quick fix for avatar image truncated issue which will cause …
This commit is contained in:
@@ -3,6 +3,7 @@ from abc import abstractmethod
|
||||
import datetime
|
||||
import hashlib
|
||||
import os
|
||||
import logging
|
||||
|
||||
from seahub.base.fields import LowerCaseCharField
|
||||
|
||||
@@ -31,6 +32,9 @@ from seahub.avatar.settings import (AVATAR_STORAGE_DIR, AVATAR_RESIZE_METHOD,
|
||||
AVATAR_THUMB_QUALITY, AUTO_GENERATE_AVATAR_SIZES,
|
||||
GROUP_AVATAR_STORAGE_DIR)
|
||||
|
||||
# Get an instance of a logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def avatar_file_path(instance=None, filename=None, size=None, ext=None):
|
||||
if isinstance(instance, Avatar):
|
||||
tmppath = [AVATAR_STORAGE_DIR]
|
||||
@@ -89,8 +93,7 @@ class AvatarBase(object):
|
||||
try:
|
||||
orig = self.avatar.storage.open(self.avatar.name, 'rb').read()
|
||||
image = Image.open(StringIO(orig))
|
||||
except IOError:
|
||||
return # What should we do here? Render a "sorry, didn't work" img?
|
||||
|
||||
quality = quality or AVATAR_THUMB_QUALITY
|
||||
(w, h) = image.size
|
||||
if w != size or h != size:
|
||||
@@ -109,6 +112,9 @@ class AvatarBase(object):
|
||||
else:
|
||||
thumb_file = ContentFile(orig)
|
||||
thumb = self.avatar.storage.save(self.avatar_name(size), thumb_file)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return # What should we do here? Render a "sorry, didn't work" img?
|
||||
|
||||
def avatar_url(self, size):
|
||||
return self.avatar.storage.url(self.avatar_name(size))
|
||||
|
Reference in New Issue
Block a user