Created
November 12, 2010 02:42
-
-
Save csytan/673646 to your computer and use it in GitHub Desktop.
blobstore tornado uploadhandler config
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
### app.yaml ### | |
- url: /upload | |
script: main.py | |
login: admin | |
### views.py ### | |
class BlobstoreUpload(BaseHandler): | |
def post(self): | |
key = self.get_argument('key') | |
attr = self.get_argument('attr') | |
next = self.get_argument('next', '/') | |
blob_key = re.findall(r'blob-key="*(\S+)', self.request.body)[0] | |
blob_info = blobstore.BlobInfo.get(blob_key) | |
entity = db.get(key) | |
setattr(entity, attr, blob_info) | |
entity.put() | |
return self.redirect(next) | |
class UploadForm(BaseHandler): | |
def get(self): | |
redirect = '/upload?' + urllib.urlencode({ | |
'key': self.current_site.key(), | |
'attr': 'default_gravatar' | |
}) | |
upload_url = blobstore.create_upload_url(redirect) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment