From 72ca0fe69c297fb7ccff09f6d9e49c26ea61aebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 9 May 2016 15:31:43 +0200 Subject: [PATCH] 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. --- pillar/application/modules/file_storage.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pillar/application/modules/file_storage.py b/pillar/application/modules/file_storage.py index 64bcea93..a2d60c16 100644 --- a/pillar/application/modules/file_storage.py +++ b/pillar/application/modules/file_storage.py @@ -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///') @file_storage.route('/gcs///') @@ -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)