def post(self): # pylint: disable=g-bad-name """Handles Object Change Notifications.""" logging.debug( '%s\n\n%s', '\n'.join(['%s: %s' % x for x in self.request.headers.iteritems()]), self.request.body) resource_state = self.request.headers['X-Goog-Resource-State'] if resource_state == 'sync': logging.info('Sync OCN message received.') elif resource_state == 'exists': logging.info('New file upload OCN message received.') data = json.loads(self.request.body) bucket = data['bucket'] object_name = data['name'] # Get Image location in GCS. gcs_image_location = '/gs/%s/%s' % (bucket, object_name) blob_key = blobstore.create_gs_key(gcs_image_location) # Try and get username from metadata. if data.has_key('metadata') and data['metadata'].has_key('owner'): owner = data['metadata']['owner'] else: owner = data['owner']['entity'] # Try to get public image URL for entry creation. image_link = None try: image_link = images.get_serving_url(blob_key, secure_url=True) except images.ObjectNotFoundError: logging.error('Could not find image link for %s.', gcs_image_location) except images.TransformationError: logging.error('Could not convert link to image: %s.', gcs_image_location) if image_link: bitdoc = Bitdoc(user=owner, image_link=image_link, file_name=object_name) logging.info('Creating Entry... %s - %s', bitdoc.user, bitdoc.image_link) # timestamp auto. bitdoc.put() # Add Task to pull queue. info = {'key': unicode(bitdoc.key()), 'image_link': unicode(image_link)} processing_task_queue.add(taskqueue.Task(payload=json.dumps(info), method='PULL'))
def ListImages(self, request): """Returns list of images to the client.""" GetEndpointsAuthUser() images = [] query = Bitdoc.all().order('-timestamp') for item in query.fetch(limit=request.limit, offset=request.offset): images.append( ListImage(user=item.user, timestamp=item.timestamp_strsafe, image_link=item.image_link, image_8bit_link=item.image_8bit_link, timestamp_8bit=item.timestamp_8bit_strsafe, key=str(item.key()))) return ListImagesResponse(images=images)
def ListImages(self, request): """Returns list of images to the client.""" GetEndpointsAuthUser() images = [] query = Bitdoc.all().order('-timestamp') for item in query.fetch(limit=request.limit, offset=request.offset): images.append( ListImage( user=item.user, timestamp=item.timestamp_strsafe, image_link=item.image_link, image_8bit_link=item.image_8bit_link, timestamp_8bit=item.timestamp_8bit_strsafe, key=str(item.key()) ) ) return ListImagesResponse(images=images)