diff --git a/flask_s3.py b/flask_s3.py index 573cc9d..a4e80b9 100644 --- a/flask_s3.py +++ b/flask_s3.py @@ -4,7 +4,10 @@ import logging import os import re import gzip -import cStringIO +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO import mimetypes from collections import defaultdict @@ -216,12 +219,16 @@ def _write_files(s3, app, static_url_loc, static_folder, files, bucket, # When we use GZIP we have to explicitly set the content type (mimetype, encoding) = mimetypes.guess_type(file_path, False) - h["content-type"] = mimetype + if mimetype: + h["content-type"] = mimetype + else: + logger.warn("Unable to detect mimetype for %s" % + file_path) with open(file_path) as fp: metadata, params = split_metadata_params(merge_two_dicts(app.config['S3_HEADERS'], h)) if should_gzip: - compressed = cStringIO.StringIO() + compressed = StringIO() z = gzip.GzipFile(os.path.basename(file_path), 'wb', 9, compressed) z.write(fp.read())