Around the houses, App Engine stylee

I'm quite aware of the depths of my e-stupidity, but the only way I could get an image out of an email attachment sent to a Google App Engine app and uploaded to S3 using Boto, was this absurd backflip (literally).

class LogSenderHandler(InboundMailHandler):    def receive(self, message):        attachments = []        if message.attachments:            if isinstance(message.attachments[0], basestring):                attachments = [message.attachments]             else:                 attachments = message.attachments        for filename, content in attachments:            img = images.Image(content.decode())            if img:                img.rotate(360)                 sitehelpers.upload_to_s3(filename,                            StringIO(img.execute_transforms(output_encoding=images.JPEG)),                            message.sender)

Yes, I did just rotate an image for the sake of it, the only way to get a stream accepted by Boto (GAE Image will just send an object), is to flip the image around 360 degrees and then execute the transformation.
Anybody out there in the land of tWeb is welcome to call me on this, but in case you are struggling and need any solution possible, this works a treat for me. Ask Jeremy Clarkson about performance.

 

Filed under  //  app engine   mail  
Comments (5)
Posted by Effisfor