Compare commits
2 Commits
191b54f113
...
b35e4030ac
| Author | SHA1 | Date | |
|---|---|---|---|
| b35e4030ac | |||
| 17c8a41229 |
22
app.py
22
app.py
@ -466,18 +466,30 @@ def serve_file(subpath):
|
||||
filesize = os.path.getsize(file_path)
|
||||
|
||||
# Figure out download flag and filename
|
||||
ask_download = request.args.get('download') == 'true'
|
||||
as_attachment = request.args.get('download') == 'true'
|
||||
filename = os.path.basename(full_path)
|
||||
|
||||
if as_attachment:
|
||||
download_name = filename
|
||||
mimetype = 'application/octet-stream'
|
||||
else:
|
||||
download_name = None
|
||||
mimetype = mime
|
||||
|
||||
|
||||
# Single send_file call with proper attachment handling
|
||||
response = send_file(
|
||||
file_path,
|
||||
mimetype=mime,
|
||||
mimetype=mimetype,
|
||||
conditional=True,
|
||||
as_attachment=ask_download,
|
||||
download_name=filename if ask_download else None
|
||||
as_attachment=as_attachment ,
|
||||
download_name=download_name
|
||||
)
|
||||
if not ask_download:
|
||||
|
||||
if as_attachment:
|
||||
response.headers['X-Content-Type-Options'] = 'nosniff'
|
||||
|
||||
if not as_attachment :
|
||||
response.headers['Content-Disposition'] = 'inline'
|
||||
response.headers['Cache-Control'] = 'public, max-age=86400'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user