Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created August 24, 2011 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamelafox/1169609 to your computer and use it in GitHub Desktop.
Save pamelafox/1169609 to your computer and use it in GitHub Desktop.
App Engine Photo Upload (with BlobStore)
from __future__ import with_statement
from google.appengine.ext import db, blobstore
from google.appengine.api import memcache, files, images
class Photo(db.Model):
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
blob_key = blobstore.BlobReferenceProperty()
url = db.StringProperty()
thumbnail_url = db.StringProperty()
def upload_blob(self, file):
file_name = files.blobstore.create(mime_type='image/png')
with files.open(file_name, 'a') as f:
f.write(file)
files.finalize(file_name)
self.blob_key = files.blobstore.get_blob_key(file_name)
self.url = images.get_serving_url(self.blob_key)
self.thumbnail_url = images.get_serving_url(self.blob_key, size=100, crop=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment