def base_post(self): """ Uploads & checks file, then delegates to ORSService for analysis. """ allowed_extensions = ["png", "jpg", "gif", "bmp", "jpeg", "bm", "svg", "tiff"] allowed_mimetypes = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp", "image/x-windows-bmp", "image/svg+xml", "image/tiff"] try: file = Uploader(self.request).size(614400).extensions(allowed_extensions).mimetypes(allowed_mimetypes).check(upload=True) chunk = self.make_chunk({"success":True, "next_msg":"Analysing..", "last":False}) self.write(chunk) self.flush() title = self.get_argument("painting-title") artist = self.get_argument("painting-artist") strategy = self.get_argument("painting-strategy") tags = json_encode(map(str.strip, (str(self.get_argument("painting-tags") or '')).split(","))) if not title: self.write(self.make_chunk({"success":False, "next_msg":"Please specify the painting's title.", "last":True})) self.finish() elif not artist: self.write(self.make_chunk({"success":False, "next_msg":"Please specify the artist.", "last":True})) self.finish() else: service = ORSService() if len(file) == 1: id = file[0].split(".")[0] service.describe_painting(id, title, artist, strategy, tags, self.async_callback(self.on_service_response)) else: self.write(self.make_chunk({"success":False, "next_msg":"No file selected for upload.", "last":True})) self.finish() except (NullRequestError, SizeLimitExceededError, WrongMimetypeError, WrongExtensionError), e: self.log.error(e.err_msg) self.write(self.make_chunk({"success":False, "next_msg":e.err_msg, "last":True})) self.finish()
def base_post(self): service = ORSService() payload = self.get_argument("payload") if not payload: self.finish("No payload detected.") return service.get_match(payload, self.async_callback(self.on_service_response))