def mongo_save_photo(upfile, display_name, photo_id): try: photo = Photo(image_file=upfile.read(), photo_id=photo_id, display_name=display_name) photo.save() except (Photo.OperationError, IOError): return False except (pymongo.errors.AutoReconnect, pymongo.errors.ServerSelectionTimeoutError, pymongo.errors.NetworkTimeout) as e: raise return True
def mongo_add(name, image): with grpc.insecure_channel('tags-service:50051') as channel: stub = tags_pb2_grpc.TagsStub(channel) response = stub.getTags(tags_pb2.ImageRequest(file=image.file.read())) ph = Photo(title='title', location='location', author=name, comment='comment', tags=response.tags) ph.photo.put(image.file) ph = ph.save() return ph