Browse Source

修复图片不存在问题

peng 2 years ago
parent
commit
1fd962d4b0
2 changed files with 13 additions and 2 deletions
  1. 12 2
      Controller/FeedBack.py
  2. 1 0
      Object/AWS/AmazonS3Util.py

+ 12 - 2
Controller/FeedBack.py

@@ -326,10 +326,12 @@ class FeedBackView(View):
             region_name = AWS_IOT_SES_ACCESS_CHINA_REGION
             aws_access_key_id = AWS_ACCESS_KEY_ID[0]
             secret_access_key = AWS_SECRET_ACCESS_KEY[0]
+            source_bucket = 'push'
         else:  # 国外
             region_name = AWS_SES_ACCESS_REGION
             aws_access_key_id = AWS_ACCESS_KEY_ID[1]
             secret_access_key = AWS_SECRET_ACCESS_KEY[1]
+            source_bucket = 'foreignpush'
         equipment_info_id = equipment_info_id[1:]
         now_time = int(time.time())
         is_st = int(is_st)
@@ -343,14 +345,22 @@ class FeedBackView(View):
                 file_path = '{uid}/{channel}/{event_time}.jpeg'.format(uid=uid,
                                                                        channel=channel,
                                                                        event_time=event_time)
-                s3.copy_obj('push', 'push-inaccurate', file_path)
+                try:
+                    s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
+                except Exception as e:
+                    if e.response['Error']['Code'] == "404":
+                        return response.json(173)
             else:
                 for index in range(3):
                     file_path = '{uid}/{channel}/{event_time}_{index}.jpeg'.format(uid=uid,
                                                                                    channel=channel,
                                                                                    event_time=event_time,
                                                                                    index=index)
-                    s3.copy_obj('push', 'push-inaccurate', file_path)
+                    try:
+                        s3.copy_obj(source_bucket, 'push-inaccurate', file_path)
+                    except Exception as e:
+                        if e.response['Error']['Code'] == "404":
+                            continue
             PushInaccurateFeedback.objects.create(equipment_info_id=equipment_info_id,
                                                   user_id=user_id, event_type=event_type,
                                                   uid=uid, channel=channel, add_time=now_time,

+ 1 - 0
Object/AWS/AmazonS3Util.py

@@ -123,3 +123,4 @@ class AmazonS3Util:
             'Key': file_key
         }
         self.session_conn.meta.client.copy(source_dict, to_bucket, file_key)
+