Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue_django_test
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
周田
vue_django_test
Commits
170eb867
Commit
170eb867
authored
Aug 23, 2023
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:修复 http 响应头无法使用中文
parent
0614881a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
Upload.vue
frontend/src/views/Upload.vue
+1
-1
views.py
vue_django/views.py
+14
-11
No files found.
frontend/src/views/Upload.vue
View file @
170eb867
...
@@ -34,7 +34,7 @@ const downloadFile = () => {
...
@@ -34,7 +34,7 @@ const downloadFile = () => {
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
"multipart/form-data"
});
const
blob
=
new
Blob
([
res
.
data
],
{
type
:
"multipart/form-data"
});
const
link
=
document
.
createElement
(
"a"
);
const
link
=
document
.
createElement
(
"a"
);
link
.
href
=
window
.
URL
.
createObjectURL
(
blob
);
link
.
href
=
window
.
URL
.
createObjectURL
(
blob
);
link
.
download
=
res
.
headers
[
"filename"
]
link
.
download
=
decodeURIComponent
(
res
.
headers
[
"filename"
]);
link
.
click
();
link
.
click
();
});
});
console
.
log
(
"downloadFile"
);
console
.
log
(
"downloadFile"
);
...
...
vue_django/views.py
View file @
170eb867
import
os
import
os
import
urllib.parse
from
django.conf
import
settings
from
django.conf
import
settings
from
django.http
import
FileResponse
from
django.http
import
FileResponse
from
django.shortcuts
import
render
from
django.shortcuts
import
render
...
@@ -42,18 +44,19 @@ def download(request):
...
@@ -42,18 +44,19 @@ def download(request):
protocol_name
=
request
.
GET
.
get
(
'protocol_name'
)
protocol_name
=
request
.
GET
.
get
(
'protocol_name'
)
version
=
request
.
GET
.
get
(
'version'
)
version
=
request
.
GET
.
get
(
'version'
)
print
(
protocol_name
)
print
(
version
)
file_path
=
os
.
path
.
join
(
settings
.
BASE_DIR
,
'protocol_raw_files'
,
protocol_name
,
version
)
file_path
=
os
.
path
.
join
(
settings
.
BASE_DIR
,
'protocol_raw_files'
,
protocol_name
,
version
)
print
(
file_path
)
for
root
,
_
,
files
in
os
.
walk
(
file_path
):
for
root
,
_
,
files
in
os
.
walk
(
file_path
):
print
(
f
"root ==> {root}"
)
for
file
in
files
:
file_path
=
os
.
path
.
join
(
root
,
files
[
1
])
# if file != 'xdc.sqlite':
response
=
FileResponse
(
open
(
file_path
,
'rb'
))
# continue
response
[
'Content-Disposition'
]
=
'inline; filename='
+
os
.
path
.
basename
(
file_path
)
file_path
=
os
.
path
.
join
(
root
,
files
[
3
])
response
[
'Content-Type'
]
=
'multipart/form-data'
# 适配中文
response
[
'filename'
]
=
os
.
path
.
basename
(
file_path
)
file_name
=
urllib
.
parse
.
quote
(
os
.
path
.
basename
(
file_path
))
return
response
response
=
FileResponse
(
open
(
file_path
,
'rb'
))
response
[
'Content-Disposition'
]
=
'inline; filename='
+
file_name
response
[
'Content-Type'
]
=
'multipart/form-data'
response
[
'filename'
]
=
file_name
return
response
return
Response
(
status
=
status
.
HTTP_200_OK
)
return
Response
(
status
=
status
.
HTTP_200_OK
)
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