74b2dc4d by 冯轩

merge

2 parents bcc43570 612ad465
...@@ -70,6 +70,7 @@ from apps.doc.ocr.ecm import ECM ...@@ -70,6 +70,7 @@ from apps.doc.ocr.ecm import ECM
70 import time 70 import time
71 from django.http import HttpResponse 71 from django.http import HttpResponse
72 from django.utils.encoding import escape_uri_path 72 from django.utils.encoding import escape_uri_path
73 from PIL import Image
73 74
74 75
75 class CustomDate(fields.Date): 76 class CustomDate(fields.Date):
...@@ -1155,10 +1156,19 @@ class DocView(DocGenericView, DocHandler): ...@@ -1155,10 +1156,19 @@ class DocView(DocGenericView, DocHandler):
1155 random_int = random.randint(0, consts.TIME_NUM) 1156 random_int = random.randint(0, consts.TIME_NUM)
1156 metadata_version_id = str(int(time.time()) - random_int) 1157 metadata_version_id = str(int(time.time()) - random_int)
1157 1158
1159 # 现在不只接受pdf 图片也接收
1158 pdf_file = request.FILES.get('pdf_file') 1160 pdf_file = request.FILES.get('pdf_file')
1161 file_suffux = ''
1159 if isinstance(pdf_file.name, str): 1162 if isinstance(pdf_file.name, str):
1160 if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): 1163 # if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
1161 self.invalid_params(msg='invalid params: not a PDF file') 1164 # self.invalid_params(msg='invalid params: not a PDF file')
1165 if '.' in pdf_file.name:
1166 file_suffux = pdf_file.name.split('.')[-1]
1167 else:
1168 self.invalid_params(msg='invalid params: invalid file name')
1169 else:
1170 self.invalid_params(msg='invalid params: invalid file name')
1171
1162 1172
1163 business_type = request.POST.get('business_type', '') 1173 business_type = request.POST.get('business_type', '')
1164 document_scheme = request.POST.get('document_scheme', '') 1174 document_scheme = request.POST.get('document_scheme', '')
...@@ -1169,7 +1179,19 @@ class DocView(DocGenericView, DocHandler): ...@@ -1169,7 +1179,19 @@ class DocView(DocGenericView, DocHandler):
1169 # business_type = random.choice(consts.BUSINESS_TYPE_LIST) 1179 # business_type = random.choice(consts.BUSINESS_TYPE_LIST)
1170 # business_type = consts.BUSINESS_TYPE_LIST[0] 1180 # business_type = consts.BUSINESS_TYPE_LIST[0]
1171 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) 1181 tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id))
1172 file_write(pdf_file, tmp_save_path) 1182 # real_save_path 是实际后缀名的保存路径,tmp_save_path 后缀名一定是pdf,是为了后续流程保持原有逻辑保留的
1183 real_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.{1}'.format(metadata_version_id, file_suffux.lower()))
1184 file_write(pdf_file, real_save_path)
1185 if file_suffux.lower() != 'pdf':
1186 try:
1187 image = Image.open(pdf_file)
1188 image = image.convert("RGB")
1189 image.save(tmp_save_path, "PDF", resolution=100.0)
1190 self.running_log.info('[mock upload img] [图片已成功转换为 PDF 文件={0}] [path={1}]'.format(pdf_file.name, tmp_save_path))
1191 except Exception as e:
1192 self.running_log.info('[mock upload img fail] [不支持的文件类型={0}]'.format(pdf_file.name))
1193 self.invalid_params(msg='invalid params: not support file type')
1194
1173 1195
1174 try: 1196 try:
1175 file = fitz.Document(tmp_save_path) 1197 file = fitz.Document(tmp_save_path)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!