- Nginx作为静态资源web服务之文件读取
- 后端将文件保存到服务器固定位置,将文件位置返回给前端,前端通过nginx读取静态文件即可
- 文件读取需要用到的几个配置:https://www.cnblogs.com/duguxiaobiao/p/9128804.html
- 后端将文件保存后将其读出输出二进制流给前端
- 这种方式会在服务器上形成临时文件,后续需要考虑定期删除等问题
with open(filepath, 'rb') as fp:
response = Response(fp.read(), content_type="application/vnd.openmosix-officiated.spreadsheet.sheet")
response.status_code = 200
return response
- pandas可以不需要形成临时文件,直接输出二进制流,节省了临时文件存取删除的步骤
bio = BytesIO()
writer = pd.ExcelWriter(bio, engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1', index=False)
writer.save()
bio.seek(0)
response = Response(bio.read(), content_type="application/vnd.openmosix-officiated.spreadsheet.sheet")
response.status_code = 200
return response