inital work to use streams/chunks when handling uploaded assets
This commit is contained in:
committed by
David Baumgold
parent
18861e4ef9
commit
7d7eee7d0d
@@ -113,7 +113,7 @@ class ContentStore(object):
|
||||
'''
|
||||
raise NotImplementedError
|
||||
|
||||
def generate_thumbnail(self, content):
|
||||
def generate_thumbnail(self, content, tempfile_path=None):
|
||||
thumbnail_content = None
|
||||
# use a naming convention to associate originals with the thumbnail
|
||||
thumbnail_name = StaticContent.generate_thumbnail_name(content.location.name)
|
||||
@@ -129,7 +129,10 @@ class ContentStore(object):
|
||||
# My understanding is that PIL will maintain aspect ratios while restricting
|
||||
# the max-height/width to be whatever you pass in as 'size'
|
||||
# @todo: move the thumbnail size to a configuration setting?!?
|
||||
im = Image.open(StringIO.StringIO(content.data))
|
||||
if tempfile_path is None:
|
||||
im = Image.open(StringIO.StringIO(content.data))
|
||||
else:
|
||||
im = Image.open(tempfile_path)
|
||||
|
||||
# I've seen some exceptions from the PIL library when trying to save palletted
|
||||
# PNG files to JPEG. Per the google-universe, they suggest converting to RGB first.
|
||||
|
||||
@@ -35,8 +35,11 @@ class MongoContentStore(ContentStore):
|
||||
with self.fs.new_file(_id=id, filename=content.get_url_path(), content_type=content.content_type,
|
||||
displayname=content.name, thumbnail_location=content.thumbnail_location,
|
||||
import_path=content.import_path) as fp:
|
||||
|
||||
fp.write(content.data)
|
||||
if hasattr(content.data, '__iter__'):
|
||||
for chunk in content.data:
|
||||
fp.write(chunk)
|
||||
else:
|
||||
fp.write(content.data)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user