Default mimetype when detection fails should be application/octet-stream #3106
Unanswered
AbdealiLoKo
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm a long time flask and django user. I was trying out fastapi and was trying out some StaticFile stuff when I noticed some differences. Wanted to highlight them here to understand whether the behavior should be changed
When I use the
starlette.responses.FileResponseclass I noticed that when I was sending binary files, I was receiving a contentType astext/plain.On digging into it, I noticed this was causing it: https://github.com/Kludex/starlette/blob/0.51.0/starlette/responses.py#L317
I was wondering if it was a purposeful decision and whether I could change the default ... and noticed this issue: #1027 (comment)
Where the discussion was about trying to follow flask/django's standard in such cases for UploadedFiles.
I see that both Django and Flask are using application/octet-stream in these cases:
Django: https://github.com/django/django/blob/6.0.1/django/views/static.py#L59
Flask / Werkzeug: https://github.com/pallets/werkzeug/blob/3.1.5/src/werkzeug/utils.py#L441
Workaround: For now, I am explicitly sending the mimetype myself. And that got my UI working...
Long Term: I was curious to learn if there was a reason to keep
text/plainas the default. And whether I should be handling this in some other place in my stack like in the UI etc.Beta Was this translation helpful? Give feedback.
All reactions