django - Downloading file using HttpResponse throwing error as "body size is too long" for large files (>5MB)
问题描述
I am retrieving file from s3 bucket and returning content as a file as shown below:
s3 = boto3.resource("s3")
object = s3.Object(bucket-name,s3_key)
text = object.get()['Body']
response = FileResponse(text)
response['Content-Disposition'] = 'attachment;filename=sample.xls'
return response
But i am getting error as "body size is too long"
while returning file.
解决方案
尝试:
from django.core.servers.basehttp import FileWrapper
from django.http import FileResponse
s3 = boto3.resource("s3")
object = s3.Object(bucket-name,s3_key)
text = object.get()['Body']
FileResponse(FileWrapper(file(filename, 'rb')), content_type='application/x-zip-compressed')
response['Content-Disposition'] = 'attachment; filename=sample.xls'
return response
这将对您有所帮助。
推荐阅读
- javascript - 我可以在javascript中用字符串名称调用一些帮助函数吗
- typo3 - PHP strict_types 和与不可见 TYPO3 记录的关系
- django - django频道安装错误
- python - 将数据框中的字典列表转换为字符串列表 - 熊猫
- php - 无法通过 Phonegap 和 PHP 将图像上传到 Linux 服务器
- php - 将多个外部 MSSQL 表中的多个组合 PHP 表单数据添加到一个主表中
- ios - UIAlertController 在警报操作时移动到另一个控制器 - Swift
- ios - 如何在 iOS 中实现彗星聊天时修复“无效的 API 密钥格式”
- ms-project - MS Project 自动计划
- python - 如何修改表格的位置