New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit file MIME-type when writing with GridFS backend #28
Add explicit file MIME-type when writing with GridFS backend #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for value not None, I'll merge it, but I think it won't solve the fact that this value is almost never set by Werkzeug
flask_fs/backends/gridfs.py
Outdated
'filename': filename | ||
} | ||
|
||
if hasattr(content, 'content_type'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test that it's not None
because most of the time Werkzeug set it to None
(never succed to have another value).
if getattr(content, 'content_type'):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done. On my end, I always get a proper "content_type" in "request.files" if the originating request is set properly (i.e. the "Content-Type" header is set, thus making Werkzeug guess it).
e1cc98d
to
7b58ff6
Compare
Thanks! I'll probably release it today. |
Oh nice! Thanks a lot! |
When using the GridFS backend and trying to serve files with it, the MIME-type cannot be found by Flask on the returned file. When writing a file to GridFS, the MIME-type should be included allowing to retrieve it when serving the file.
Run the following sample app to reproduce the issue:
Perform the following requests to observe the issue:
Packages versions
Flask (0.12.2)
flask-fs (0.6.0)