Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
credit-report-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
credit-report-api
Commits
4a19fb82
Commit
4a19fb82
authored
Aug 23, 2019
by
张鹏程
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改上传文件bug
parent
fd33a8aa
Pipeline
#931
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
18 deletions
+45
-18
Base_Handler.py
handler/Base_Handler.py
+2
-1
ReportAnalysis_Handler.py
handler/ReportAnalysis_Handler.py
+0
-1
UpLoadFiles_Handler.py
handler/UpLoadFiles_Handler.py
+43
-16
No files found.
handler/Base_Handler.py
View file @
4a19fb82
...
@@ -5,7 +5,8 @@ import tornado.web
...
@@ -5,7 +5,8 @@ import tornado.web
class
BaseHandler
(
tornado
.
web
.
RequestHandler
):
class
BaseHandler
(
tornado
.
web
.
RequestHandler
):
# 初始化映射关系
# 初始化映射关系
def
prepare
(
self
):
def
prepare
(
self
):
self
.
set_header
(
'Content-Type'
,
"application/json; charset=UTF-8"
)
self
.
set_header
(
'Content-Type'
,
"application/json; charset=UTF-8;multipart/form-data"
)
# self.set_header('Content-Type':)
...
...
handler/ReportAnalysis_Handler.py
View file @
4a19fb82
...
@@ -12,7 +12,6 @@ from service.QueryInfomation_Service import QueryInfomation # 查询记录
...
@@ -12,7 +12,6 @@ from service.QueryInfomation_Service import QueryInfomation # 查询记录
from
service.Base_Service
import
Result
# 返回结果存储
from
service.Base_Service
import
Result
# 返回结果存储
from
service.InitHtml_Service
import
InitHtml
# 初始化HTML
from
service.InitHtml_Service
import
InitHtml
# 初始化HTML
class
ReportAnalysis
(
BaseHandler
):
class
ReportAnalysis
(
BaseHandler
):
def
post
(
self
):
def
post
(
self
):
self
.
_filepath
=
self
.
get_argument
(
'filename'
,
default
=
None
)
self
.
_filepath
=
self
.
get_argument
(
'filename'
,
default
=
None
)
...
...
handler/UpLoadFiles_Handler.py
View file @
4a19fb82
...
@@ -6,30 +6,57 @@ from config import settings
...
@@ -6,30 +6,57 @@ from config import settings
class
UpLoadFiles
(
BaseHandler
):
class
UpLoadFiles
(
BaseHandler
):
def
post
(
self
):
def
post
(
self
):
self
.
_filepath
=
self
.
get_argument
(
'filepath'
,
default
=
None
)
# self._filepath = self.get_arguments('filepath', default=None)
try
:
if
self
.
_filepath
==
None
or
self
.
_filepath
==
''
:
self
.
_filepath
=
self
.
request
.
files
[
'filepath'
]
except
:
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Params_Error
,
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Params_Error
,
mssage
=
JsonUtil
.
Constants
.
Msg_Params_Error
.
format
(
'filepath'
,
self
.
_filepath
)))
mssage
=
JsonUtil
.
Constants
.
Msg_Params_Error
.
format
(
'filepath'
,
'无参数'
)))
self
.
flush
()
self
.
flush
()
else
:
file_name
=
None
filepath
=
self
.
_filepath
file_body
=
None
try
:
if
self
.
_filepath
:
with
open
(
filepath
,
'rb'
)
as
f
:
for
meta
in
self
.
_filepath
:
with
open
(
settings
.
HTML_PATH
+
'/'
+
self
.
_filepath
.
split
(
'/'
)[
-
1
],
'wb+'
)
as
f_to
:
file_name
=
meta
[
'filename'
]
f_to
.
write
(
f
.
read
())
file_body
=
meta
[
'body'
]
if
file_name
:
if
file_body
:
try
:
with
open
(
settings
.
HTML_PATH
+
'/'
+
file_name
,
'wb+'
)
as
f_to
:
f_to
.
write
(
file_body
)
f_to
.
close
()
f_to
.
close
()
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Success
,
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Success
,
mssage
=
JsonUtil
.
Constants
.
Msg_Success
,
mssage
=
JsonUtil
.
Constants
.
Msg_Success
,
report
=
'文件上传成功'
report
=
'文件上传成功'
))
))
f
.
close
()
self
.
flush
()
self
.
finish
()
except
IOError
as
e
:
# with open(filepath, 'rb') as f:
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_FileUp_Error
,
# with open(settings.HTML_PATH+'/'+self._filepath.split('/')[-1],'wb+') as f_to:
mssage
=
JsonUtil
.
Constants
.
Msg_FileUp_Error
))
# f_to.write(f.read())
# f_to.close()
# self.write(JsonUtil.build_json(code=JsonUtil.Constants.Code_Success,
# mssage=JsonUtil.Constants.Msg_Success,
# report='文件上传成功'
# ))
# f.close()
self
.
flush
()
self
.
finish
()
except
IOError
as
e
:
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_FileUp_Error
,
mssage
=
JsonUtil
.
Constants
.
Msg_FileUp_Error
))
self
.
flush
()
else
:
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Params_Error
,
mssage
=
JsonUtil
.
Constants
.
Msg_Params_Error
.
format
(
'文件body无内容'
,
file_body
)))
self
.
flush
()
self
.
flush
()
else
:
self
.
write
(
JsonUtil
.
build_json
(
code
=
JsonUtil
.
Constants
.
Code_Params_Error
,
mssage
=
JsonUtil
.
Constants
.
Msg_Params_Error
.
format
(
'文件名称不存在'
,
file_name
)))
self
.
flush
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment