From 7d7eee7d0d5585d24742fb4857ef5bbe4439d222 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 8 May 2013 12:10:25 -0400 Subject: [PATCH] inital work to use streams/chunks when handling uploaded assets --- common/lib/xmodule/xmodule/contentstore/content.py | 7 +++++-- common/lib/xmodule/xmodule/contentstore/mongo.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/contentstore/content.py b/common/lib/xmodule/xmodule/contentstore/content.py index 64069ce9fa..b0d8c357a3 100644 --- a/common/lib/xmodule/xmodule/contentstore/content.py +++ b/common/lib/xmodule/xmodule/contentstore/content.py @@ -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. diff --git a/common/lib/xmodule/xmodule/contentstore/mongo.py b/common/lib/xmodule/xmodule/contentstore/mongo.py index ce75adc1ee..8cb4143fd9 100644 --- a/common/lib/xmodule/xmodule/contentstore/mongo.py +++ b/common/lib/xmodule/xmodule/contentstore/mongo.py @@ -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