file md5 error

Brightcells 8 years ago
parent
commit
435363c27a
1 changed files with 6 additions and 5 deletions
  1. 6 5
      utils/storage_utils.py

+ 6 - 5
utils/storage_utils.py

@@ -22,14 +22,15 @@ class DotDict(dict):
22 22
 
23 23
 
24 24
 @transaction.atomic
25
-def file_save(photo=None, photo_path=None, prefix='img', ext='jpeg', watermark=False, thumbnail=False):
25
+def file_save(file_=None, file_path=None, prefix='img', ext='jpeg', watermark=False, thumbnail=False):
26 26
     # Photo
27
-    photo = photo or default_storage.open(photo_path)
27
+    file_ = file_ or default_storage.open(file_path)
28 28
 
29 29
     # Ext
30
-    ext = os.path.splitext(photo.name)[-1] or ext
30
+    ext = os.path.splitext(file_.name)[-1] or ext
31 31
 
32
-    photo, created = PhotoUUIDInfo.objects.select_for_update().get_or_create(photo_md5=calculate_md5(photo))
32
+    # Photo UUID Get or Create
33
+    photo, created = PhotoUUIDInfo.objects.select_for_update().get_or_create(photo_md5=calculate_md5(file_))
33 34
 
34 35
     # 照片路径
35 36
     photo_path = photo.photo_path
@@ -37,7 +38,7 @@ def file_save(photo=None, photo_path=None, prefix='img', ext='jpeg', watermark=F
37 38
         photo_path = '{}/{}{}'.format(prefix, shortuuid.uuid(), ext)
38 39
         if default_storage.exists(photo_path):
39 40
             default_storage.delete(photo_path)
40
-        default_storage.save(photo_path, photo)
41
+        default_storage.save(photo_path, file_)
41 42
 
42 43
         photo.photo_path = photo_path
43 44
         photo.save()