Add .blend to mimetypes module at import of file_storage.py

Previously we added this in override_content_type() when
`not mimetypes.inited`. However, it seems that this is never performed
when running at production, probably due to some WSGI container also using
the mimetypes module.
This commit is contained in:
Sybren A. Stüvel 2016-05-09 15:31:43 +02:00
parent 82608e60d3
commit 72ca0fe69c

View File

@ -1,5 +1,6 @@
import datetime
import logging
import mimetypes
import os
import tempfile
import uuid
@ -37,6 +38,9 @@ file_storage = Blueprint('file_storage', __name__,
template_folder='templates',
static_folder='../../static/storage', )
# Add our own extensions to the mimetypes package
mimetypes.add_type('application/x-blend', '.blend')
@file_storage.route('/gcs/<bucket_name>/<subdir>/')
@file_storage.route('/gcs/<bucket_name>/<subdir>/<path:file_path>')
@ -463,8 +467,6 @@ def override_content_type(uploaded_file):
:type uploaded_file: werkzeug.datastructures.FileStorage
"""
import mimetypes
# Possibly use the browser-provided mime type
mimetype = uploaded_file.mimetype
if '/' in mimetype:
@ -473,11 +475,6 @@ def override_content_type(uploaded_file):
# The browser's mime type is probably ok, just use it.
return
# Add our own extensions to the mimetypes package
if not mimetypes.inited:
mimetypes.init()
mimetypes.add_type('application/x-blend', '.blend')
# And then use it to set the mime type.
(mimetype, encoding) = mimetypes.guess_type(uploaded_file.filename)