Django,返回文件附件作为HttpResponse,我能得到文件大小吗?

2024-09-30 12:15:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我从weboage返回一个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()之外,还有其他方法可以做到这一点吗?在


Tags: 文件attachmentapplicationresponsecontentxlsexcelvnd

热门问题