Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
612ad465
authored
2025-05-30 15:55:31 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
init
1 parent
c8bacd75
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
src/apps/doc/views.py
src/apps/doc/views.py
View file @
612ad46
...
...
@@ -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
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment