在Flask提供的服务端向客户端发送其请求文件存在中文名文件会报错的问题,主要是编码不对造成,
可以尝试用以下方法解决,用GET
方法请求文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| if request.method == 'GET': data = { 'url':"" } FILE_PATH = "temp/" + str(no) + "/" filename = fm.GetFileFromThisRootDir(FILE_PATH, 'mp4') if len(filename)==0: return redirect('/resource') filename=filename[0] print(filename[0]) response = make_response(send_file(filename)) basename = os.path.basename(filename) response.headers["Content-Disposition"] = \ "attachment;" \ "filename*=UTF-8''{utf_filename}".format( utf_filename=quote(basename.encode('utf-8')) ) return response
|