Fix the content-type for S3 uploads of user data.

This commit is contained in:
yackob03 2013-10-25 18:18:06 -04:00
parent 78d2d6cad0
commit 1ff67f688d

View file

@ -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)