【发布时间】:2013-05-29 21:27:28
【问题描述】:
我正在从网页返回一个 Excel .XLS 文件,例如:
xls_response = HttpResponse(mimetype='application/vnd.ms-excel')
xls_response['Content-Disposition'] = 'attachment; filename=funfile.xls'
.
.
<code to generate the file - already accomplished>
.
.
return xls_response
一切都很好,但我想在发送之前查看文件大小,以便显示上次下载时的文件大小。我已经有一个模型可以存储它,但我需要弄清楚如何在将文件返回给客户端之前从xls_response object 获取文件大小。除了二进制数据的len() 之外,有没有办法做到这一点?
【问题讨论】:
标签: python django download filesize