def create_thumbnail(file_path):
    thumbnail_filename = utils.get_thumb_filename(os.path.basename(file_path))
    thumbnail_format = utils.get_image_format(os.path.splitext(file_path)[1])
    file_format = thumbnail_format.split('/')[1]

    image_from_url = cStringIO.StringIO(urllib.urlopen(file_path).read())
    image = Image.open(image_from_url)

    # Convert to RGB if necessary
    # Thanks to Limodou on DjangoSnippets.org
    # http://www.djangosnippets.org/snippets/20/
    if image.mode not in ('L', 'RGB'):
        image = image.convert('RGB')

    # scale and crop to thumbnail
    imagefit = ImageOps.fit(image, THUMBNAIL_SIZE, Image.ANTIALIAS)
    thumbnail_io = BytesIO()
    imagefit.save(thumbnail_io, format=file_format)

    thumbnail = InMemoryUploadedFile(
        thumbnail_io,
        None,
        thumbnail_filename,
        thumbnail_format,
        len(thumbnail_io.getvalue()),
        None)
    thumbnail.seek(0)

    cc = AWSCloudContainer('mediaplan')
    data = thumbnail.read()
    cc.upload_data(filename=thumbnail_filename, data=data)
    return thumbnail_filename
 def _save_file(request, uploaded_file):
     logger.info("_save_file Enter new")
     replace_char = {
         u'Ä': u'AE',
         u'Å': u'AA',
         u'Ö': u'OE',
         u'ä': u'ae',
         u'å': u'aa',
         u'ö': u'oe'
     }
     filename = os.path.splitext(uploaded_file.name)
     logger.info("_save_file 1")
     file_name = u'%s' % filename[0]
     #check for unicode characters like å,ö or ä
     for k,v in replace_char.items():
         file_name = file_name.replace(k,v)
     saved_name = file_name + "_" +(''.join(random.choice(string.ascii_uppercase + string.digits) for i in range(6))) + filename[1]
     logger.info("_save_file 2")
     cc = AWSCloudContainer('mediaplan')
     logger.info("_save_file cc created")
     uploaded_file.seek(0)
     data = uploaded_file.read()
     logger.info("_save_file calling upload_data")
     cc.upload_data(filename=saved_name, data=data)
     logger.info("_save_file upload_data returned")
     logger.info("_save_file Exit")
     return saved_name