Created
August 24, 2011 23:54
-
-
Save pamelafox/1169609 to your computer and use it in GitHub Desktop.
App Engine Photo Upload (with BlobStore)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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