Skip to content

Commit a30951e

Browse files
committed
Do not error for unknown files if send_file sends an actual file
1 parent c54c538 commit a30951e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

flask/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
513513

514514
if mimetype is None:
515515
if attachment_filename is not None:
516-
mimetype = mimetypes.guess_type(attachment_filename)[0]
516+
mimetype = mimetypes.guess_type(attachment_filename)[0] \
517+
or 'application/octet-stream'
517518

518519
if mimetype is None:
519520
if attachment_filename is not None:

tests/test_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ def test_send_file_object_without_mimetype(self):
402402
assert 'no filename is available' in str(excinfo)
403403

404404
with app.test_request_context():
405-
with pytest.raises(ValueError) as excinfo:
406-
flask.send_file(StringIO("LOL"), attachment_filename='filename')
407-
assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo)
405+
flask.send_file(StringIO("LOL"), attachment_filename='filename')
408406

409407
def test_send_file_object(self):
410408
app = flask.Flask(__name__)

0 commit comments

Comments
 (0)