see code below, remember django is just python
from sys
sys.getsizeof(obj[, default]) #returns size of a python object.
Frage
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?
Lösung
see code below, remember django is just python
from sys
sys.getsizeof(obj[, default]) #returns size of a python object.