bugfix
This commit is contained in:
parent
6a1ecfed78
commit
bd7f42475f
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import asyncio
|
||||
|
||||
import urllib
|
||||
import aiofiles
|
||||
import mimetypes
|
||||
from aiohttp.web_exceptions import HTTPNotFound
|
||||
@ -23,20 +23,21 @@ def path_decode(dpath):
|
||||
async def file_upload(request):
|
||||
pass
|
||||
|
||||
async def file_handle(request, filepath, download=False):
|
||||
async def file_response(request, filepath, download=False):
|
||||
filename = os.path.basename(filepath)
|
||||
filename = urllib.parse.quote(filename)
|
||||
debug(f'{filepath=}, {filename=}, {download=}')
|
||||
headers = {}
|
||||
if download:
|
||||
headers = {
|
||||
'Content-Disposition': f'attachment; filename="{filename}"'
|
||||
'Content-Disposition': f'attachment; filename="{filename}"; filename*=UTF-8\'\'{safe_name}'
|
||||
}
|
||||
r = web.FileResponse(filepath, chunk_size=8096, headers=headers)
|
||||
r.enable_compression()
|
||||
return r
|
||||
|
||||
async def file_download(request, filepath):
|
||||
return await file_handle(request, filepath, download=True)
|
||||
return await file_response(request, filepath, download=True)
|
||||
|
||||
async def path_download(request, params_kw, *params, **kw):
|
||||
path = params_kw.get('path')
|
||||
@ -46,7 +47,7 @@ async def path_download(request, params_kw, *params, **kw):
|
||||
fs = FileStorage()
|
||||
fp = fs.realPath(path)
|
||||
debug(f'path_download():download filename={fp}')
|
||||
return await file_handle(request, fp, download)
|
||||
return await file_response(request, fp, download)
|
||||
|
||||
rf = RegisterFunction()
|
||||
rf.register('idfile', path_download)
|
||||
|
||||
@ -64,7 +64,7 @@ from .xlsxData import XLSXData
|
||||
from .uriop import URIOp
|
||||
from .error import Success, Error, NeedLogin, NoPermission
|
||||
from .filetest import current_fileno
|
||||
from .filedownload import path_download, file_download
|
||||
from .filedownload import path_download, file_download, file_response
|
||||
from .filestorage import FileStorage, downloadfile2url
|
||||
from .serverenv import ServerEnv
|
||||
|
||||
@ -220,22 +220,6 @@ def configValue(ks):
|
||||
def visualcoding():
|
||||
return configValue('.website.visualcoding');
|
||||
|
||||
def file_download(request,path,name,coding='utf8'):
|
||||
f = openfile(path,'rb')
|
||||
b = f.read()
|
||||
f.close()
|
||||
fname = quote(name).encode(coding)
|
||||
hah = b"attachment; filename=" + fname
|
||||
# print('file head=',hah.decode(coding))
|
||||
request.setHeader(b'Content-Disposition',hah)
|
||||
request.setHeader(b'Expires',0)
|
||||
request.setHeader(b'Cache-Control',b'must-revalidate, post-check=0, pre-check=0')
|
||||
request.setHeader(b'Content-Transfer-Encoding',b'binary')
|
||||
request.setHeader(b'Pragma',b'public')
|
||||
request.setHeader(b'Content-Length',len(b))
|
||||
request.write(b)
|
||||
request.finish()
|
||||
|
||||
def paramify(data, ns):
|
||||
ac = ArgsConvert('${', '}$')
|
||||
return ac.convert(data, ns)
|
||||
@ -318,6 +302,7 @@ def initEnv():
|
||||
g.rfexe = RegisterFunction().exe
|
||||
g.stream_response = stream_response
|
||||
g.webpath = webpath
|
||||
g.file_response = file_response
|
||||
g.file_download = file_download
|
||||
g.path_download = path_download
|
||||
g.partial = partial
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user