init
Showing
1 changed file
with
25 additions
and
3 deletions
... | @@ -65,6 +65,7 @@ from celery_compare.tasks import compare, fsm_compare | ... | @@ -65,6 +65,7 @@ from celery_compare.tasks import compare, fsm_compare |
65 | from prese.compare import get_empty_result | 65 | from prese.compare import get_empty_result |
66 | from apps.doc.ocr.ecm import ECM | 66 | from apps.doc.ocr.ecm import ECM |
67 | import time | 67 | import time |
68 | from PIL import Image | ||
68 | 69 | ||
69 | 70 | ||
70 | class CustomDate(fields.Date): | 71 | class CustomDate(fields.Date): |
... | @@ -1125,10 +1126,19 @@ class DocView(DocGenericView, DocHandler): | ... | @@ -1125,10 +1126,19 @@ class DocView(DocGenericView, DocHandler): |
1125 | random_int = random.randint(0, consts.TIME_NUM) | 1126 | random_int = random.randint(0, consts.TIME_NUM) |
1126 | metadata_version_id = str(int(time.time()) - random_int) | 1127 | metadata_version_id = str(int(time.time()) - random_int) |
1127 | 1128 | ||
1129 | # 现在不只接受pdf 图片也接收 | ||
1128 | pdf_file = request.FILES.get('pdf_file') | 1130 | pdf_file = request.FILES.get('pdf_file') |
1131 | file_suffux = '' | ||
1129 | if isinstance(pdf_file.name, str): | 1132 | if isinstance(pdf_file.name, str): |
1130 | if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): | 1133 | # if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'): |
1131 | self.invalid_params(msg='invalid params: not a PDF file') | 1134 | # self.invalid_params(msg='invalid params: not a PDF file') |
1135 | if '.' in pdf_file.name: | ||
1136 | file_suffux = pdf_file.name.split('.')[-1] | ||
1137 | else: | ||
1138 | self.invalid_params(msg='invalid params: invalid file name') | ||
1139 | else: | ||
1140 | self.invalid_params(msg='invalid params: invalid file name') | ||
1141 | |||
1132 | 1142 | ||
1133 | business_type = request.POST.get('business_type', '') | 1143 | business_type = request.POST.get('business_type', '') |
1134 | document_scheme = request.POST.get('document_scheme', '') | 1144 | document_scheme = request.POST.get('document_scheme', '') |
... | @@ -1139,7 +1149,19 @@ class DocView(DocGenericView, DocHandler): | ... | @@ -1139,7 +1149,19 @@ class DocView(DocGenericView, DocHandler): |
1139 | # business_type = random.choice(consts.BUSINESS_TYPE_LIST) | 1149 | # business_type = random.choice(consts.BUSINESS_TYPE_LIST) |
1140 | # business_type = consts.BUSINESS_TYPE_LIST[0] | 1150 | # business_type = consts.BUSINESS_TYPE_LIST[0] |
1141 | tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) | 1151 | tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id)) |
1142 | file_write(pdf_file, tmp_save_path) | 1152 | # real_save_path 是实际后缀名的保存路径,tmp_save_path 后缀名一定是pdf,是为了后续流程保持原有逻辑保留的 |
1153 | real_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.{1}'.format(metadata_version_id, file_suffux.lower())) | ||
1154 | file_write(pdf_file, real_save_path) | ||
1155 | if file_suffux.lower() != 'pdf': | ||
1156 | try: | ||
1157 | image = Image.open(pdf_file) | ||
1158 | image = image.convert("RGB") | ||
1159 | image.save(tmp_save_path, "PDF", resolution=100.0) | ||
1160 | self.running_log.info('[mock upload img] [图片已成功转换为 PDF 文件={0}] [path={1}]'.format(pdf_file.name, tmp_save_path)) | ||
1161 | except Exception as e: | ||
1162 | self.running_log.info('[mock upload img fail] [不支持的文件类型={0}]'.format(pdf_file.name)) | ||
1163 | self.invalid_params(msg='invalid params: not support file type') | ||
1164 | |||
1143 | 1165 | ||
1144 | try: | 1166 | try: |
1145 | file = fitz.Document(tmp_save_path) | 1167 | file = fitz.Document(tmp_save_path) | ... | ... |
-
Please register or sign in to post a comment