|
|
@ -8,7 +8,7 @@ |
|
|
|
:copyright: © 2010 by the Pallets team. |
|
|
|
:copyright: © 2010 by the Pallets team. |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
import io |
|
|
|
import os |
|
|
|
import os |
|
|
|
import socket |
|
|
|
import socket |
|
|
|
import sys |
|
|
|
import sys |
|
|
@ -510,6 +510,9 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, |
|
|
|
Filenames are encoded with ASCII instead of Latin-1 for broader |
|
|
|
Filenames are encoded with ASCII instead of Latin-1 for broader |
|
|
|
compatibility with WSGI servers. |
|
|
|
compatibility with WSGI servers. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.1 |
|
|
|
|
|
|
|
Partial content supports bytesIO |
|
|
|
|
|
|
|
|
|
|
|
:param filename_or_fp: the filename of the file to send. |
|
|
|
:param filename_or_fp: the filename of the file to send. |
|
|
|
This is relative to the :attr:`~Flask.root_path` |
|
|
|
This is relative to the :attr:`~Flask.root_path` |
|
|
|
if a relative path is specified. |
|
|
|
if a relative path is specified. |
|
|
@ -593,6 +596,12 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, |
|
|
|
mtime = os.path.getmtime(filename) |
|
|
|
mtime = os.path.getmtime(filename) |
|
|
|
fsize = os.path.getsize(filename) |
|
|
|
fsize = os.path.getsize(filename) |
|
|
|
headers['Content-Length'] = fsize |
|
|
|
headers['Content-Length'] = fsize |
|
|
|
|
|
|
|
elif isinstance(file, io.BytesIO): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
fsize = file.getbuffer().nbytes |
|
|
|
|
|
|
|
except AttributeError: |
|
|
|
|
|
|
|
fsize = len(file.getvalue()) |
|
|
|
|
|
|
|
headers['Content-Length'] = fsize |
|
|
|
data = wrap_file(request.environ, file) |
|
|
|
data = wrap_file(request.environ, file) |
|
|
|
|
|
|
|
|
|
|
|
rv = current_app.response_class(data, mimetype=mimetype, headers=headers, |
|
|
|
rv = current_app.response_class(data, mimetype=mimetype, headers=headers, |
|
|
|