소스 검색

优化upLoadFile

guanhailong 2 년 전
부모
커밋
401f34bf02
1개의 변경된 파일11개의 추가작업 그리고 16개의 파일을 삭제
  1. 11 16
      AdminController/VersionManagementController.py

+ 11 - 16
AdminController/VersionManagementController.py

@@ -104,7 +104,7 @@ class VersionManagement(View):
             return response.json(500, repr(e))
 
     def upLoadFile(self, request, request_dict, response):
-        # file = request.FILES.get('file', None)
+        file = request.FILES.get('file', None)
         mci = request_dict.get('mci', '')
         lang = request_dict.get('lang', '')
         ESN = request_dict.get('ESN', '')
@@ -114,7 +114,7 @@ class VersionManagement(View):
         Description = request_dict.get('Description', '')
         status = request_dict.get('status', 0)
 
-        if not all([mci, lang, ESN, max_ver, channel, resolutionRatio]):
+        if not all([file, mci, lang, ESN, max_ver, channel, resolutionRatio]):
             return response.json(444)
 
         try:
@@ -124,9 +124,7 @@ class VersionManagement(View):
             # 文件名为设备版本,最后一个'.'的前面为软件版本,后面为设备规格名称
             # V2.2.4.16E201252CA,软件版本:2.2.4,设备规格名称:16E201252CA
             # V1.7.2.36C11680X30411F000600000150001Z,软件版本:1.7.2,设备规格名称:36C11680X30411F000600000150001Z
-
-            # file_name = str(file)  # 文件名
-            file_name = 'V4.1.7.823C01552AA'
+            file_name = str(file)  # 文件名
             # .img和.tar.gz文件
             file_type_index = file_name.find('.img')
             if file_type_index == -1:
@@ -140,12 +138,10 @@ class VersionManagement(View):
             chipModelList2Code = code[:4]  # 主芯片
             type = code[8:10]  # 设备机型
             companyCode = code[-1:]  # 公司代码
-            # fileSize = file.size
-            fileSize = 188886
+            fileSize = file.size
             filePath = '/'.join(('static/otapack', mci, lang, file_name))
-            # file_data = file.read()
-            # fileMd5 = hashlib.md5(file_data).hexdigest()
-            fileMd5 = ''
+            file_data = file.read()
+            fileMd5 = hashlib.md5(file_data).hexdigest()
             data_dict = {'mci': mci, 'lang': lang, 'ESN': ESN, 'max_ver': max_ver, 'channel': channel,
                          'resolutionRatio': resolutionRatio, 'Description': Description, 'status': status,
                          'version': version, 'softwareVersion': softwareVersion, 'code': code,
@@ -164,14 +160,13 @@ class VersionManagement(View):
                 os.makedirs(upload_path)
             # 文件上传
             full_name = upload_path + file_name
-            # if os.path.exists(full_name):  # 删除同名文件
-            #     os.remove(full_name)
-            # with open(full_name, 'wb+') as write_file:
-            #     for chunk in file.chunks():
-            #         write_file.write(chunk)
+            if os.path.exists(full_name):  # 删除同名文件
+                os.remove(full_name)
+            with open(full_name, 'wb+') as write_file:
+                for chunk in file.chunks():
+                    write_file.write(chunk)
             return response.json(0)
         except Exception as e:
-            print(e)
             return response.json(500, repr(e))
 
     def editVersionInformation(self, request_dict, response):