def generate_endpoint(self, request): ''' Generate and endpoint to upload something for the content editor. ''' # Create an asset which is marked as uploading. asset = Asset().put() asset_key = asset.urlsafe() target_key = request.target handler_url = '/_assets/blob_uploaded/%s' % asset_key if target_key and len(target_key): handler_url += '/%s' % target_key return messages.Endpoint(endpoints=[blobstore.create_upload_url(handler_url)])
def attach_avatar(self, request): ''' Attach an avatar to a project or profile. ''' target_key = ndb.Key(urlsafe=self.decrypt(request.target)) if not target_key: raise remote.ApplicationError('no target provided for image') target = target_key.get() if not target: raise remote.ApplicationError('no target found for image') asset = Asset(kind='a').put() handler_url = '/_assets/blob_uploaded/%s/%s' % (asset.urlsafe(), target_key.urlsafe()) return messages.AttachAvatarEndpoint(endpoint=blobstore.create_upload_url(handler_url))