我正在从 s3 存储桶中检索文件并将内容作为文件返回,如下所示:
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
但是我在返回文件时收到错误"body size is too long"
。
尝试:
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
这将对您有所帮助。