From 1ff67f688df1fef4ac43079dba7af8f3208c79f4 Mon Sep 17 00:00:00 2001 From: yackob03 Date: Fri, 25 Oct 2013 18:18:06 -0400 Subject: [PATCH] Fix the content-type for S3 uploads of user data. --- data/userfiles.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/data/userfiles.py b/data/userfiles.py index 7c017090f..c63d8fe53 100644 --- a/data/userfiles.py +++ b/data/userfiles.py @@ -1,10 +1,14 @@ import boto import os +import logging from boto.s3.key import Key from uuid import uuid4 +logger = logging.getLogger(__name__) + + class S3FileWriteException(Exception): pass @@ -20,7 +24,9 @@ class UserRequestFiles(object): def store_file(self, flask_file): file_id = str(uuid4()) full_key = os.path.join(self._prefix, file_id) - k = Key(full_key) + k = Key(self._bucket, full_key) + logger.debug('Setting s3 content type to: %s' % flask_file.content_type) + k.set_metadata('Content-Type', flask_file.content_type) bytes_written = k.set_contents_from_file(flask_file) if bytes_written == 0: @@ -30,5 +36,5 @@ class UserRequestFiles(object): def get_file_url(self, file_id, expires_in=300): full_key = os.path.join(self._prefix, file_id) - k = Key(full_key) + k = Key(self._bucket, full_key) return k.generate_url(expires_in)