8ddb1d4c by 冯轩

Merge branch 'feature/CHINARPA-5619'

2 parents 140571d0 612ad465
......@@ -65,6 +65,7 @@ from celery_compare.tasks import compare, fsm_compare
from prese.compare import get_empty_result
from apps.doc.ocr.ecm import ECM
import time
from PIL import Image
class CustomDate(fields.Date):
......@@ -1125,10 +1126,19 @@ class DocView(DocGenericView, DocHandler):
random_int = random.randint(0, consts.TIME_NUM)
metadata_version_id = str(int(time.time()) - random_int)
# 现在不只接受pdf 图片也接收
pdf_file = request.FILES.get('pdf_file')
file_suffux = ''
if isinstance(pdf_file.name, str):
if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
self.invalid_params(msg='invalid params: not a PDF file')
# if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
# self.invalid_params(msg='invalid params: not a PDF file')
if '.' in pdf_file.name:
file_suffux = pdf_file.name.split('.')[-1]
else:
self.invalid_params(msg='invalid params: invalid file name')
else:
self.invalid_params(msg='invalid params: invalid file name')
business_type = request.POST.get('business_type', '')
document_scheme = request.POST.get('document_scheme', '')
......@@ -1139,7 +1149,19 @@ class DocView(DocGenericView, DocHandler):
# business_type = random.choice(consts.BUSINESS_TYPE_LIST)
# business_type = consts.BUSINESS_TYPE_LIST[0]
tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id))
file_write(pdf_file, tmp_save_path)
# real_save_path 是实际后缀名的保存路径,tmp_save_path 后缀名一定是pdf,是为了后续流程保持原有逻辑保留的
real_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.{1}'.format(metadata_version_id, file_suffux.lower()))
file_write(pdf_file, real_save_path)
if file_suffux.lower() != 'pdf':
try:
image = Image.open(pdf_file)
image = image.convert("RGB")
image.save(tmp_save_path, "PDF", resolution=100.0)
self.running_log.info('[mock upload img] [图片已成功转换为 PDF 文件={0}] [path={1}]'.format(pdf_file.name, tmp_save_path))
except Exception as e:
self.running_log.info('[mock upload img fail] [不支持的文件类型={0}]'.format(pdf_file.name))
self.invalid_params(msg='invalid params: not support file type')
try:
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!