문제

I am returning an Excel .XLS file from a weboage, like:

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

Everything is fine, but I'd like to see what the file size is before sending it, so I can show the file size the last time it was downloaded. I have a model already that will store this, but I need to figure out how to get the file size from the xls_response object before it is returned to the client. Is there a way to do this, other than perhaps just the len() of its binary data?

도움이 되었습니까?

해결책

see code below, remember django is just python

from sys

sys.getsizeof(obj[, default]) #returns size of a python object.

http://docs.python.org/2/library/sys.html#sys.getsizeof

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top