mirror of
https://github.com/wassname/flask-s3.git
synced 2026-06-27 15:50:06 +08:00
Fix for Python 3 and warning for unknown mimetype
This commit is contained in:
+10
-3
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user