def post(self): ''' Creates a picture and corresponding activity. Then picture is propagated to all trusted contacts. Errors are stored inside activity. ''' filebody = self.request.body filename = self.get_argument("qqfile") try: tag = self.get_argument("tag") except: tag = "all" filetype = mimetypes.guess_type(filename)[0] or \ 'application/octet-stream' if filebody: picture = Picture( title = "New Picture", path=filename, contentType=filetype, authorKey = UserManager.getUser().key, author = UserManager.getUser().name, isMine = True, isFile = True, tags = [tag] ) picture.save() picture.put_attachment(content=filebody, name=filename) thumbnail = self.get_thumbnail(filebody, filename, (200, 200)) thbuffer = thumbnail.read() picture.put_attachment(thbuffer, "th_" + filename) os.remove("th_" + filename) preview = self.get_thumbnail(filebody, filename, (1000, 1000)) picture.put_attachment(preview.read(), "prev_" + filename) os.remove("th_" + filename) picture.save() self.create_owner_creation_activity( picture, "publishes", "picture") self.send_files_to_contacts("pictures/contact/", fields = { "json": str(picture.toJson(localized=False)) }, files = [("picture", str(picture.path), thbuffer)], tag=tag) logger.info("Picture %s successfuly posted." % filename) self.return_json(picture.toJson(), 201) else: self.return_failure("No picture posted.", 400)
def post(self): ''' Creates a picture and corresponding activity. Then picture is propagated to all trusted contacts. Errors are stored inside activity. ''' file = self.request.files['picture'][0] if file: filebody = file["body"] filename = file['filename'] picture = Picture( title = "New Picture", path = filename, contentType =file["content_type"], authorKey = UserManager.getUser().key, author = UserManager.getUser().name, isFile = True ) picture.save() picture.put_attachment(filebody, filename) thumbnail = self.get_thumbnail(filebody, filename, (200, 200)) thbuffer = thumbnail.read() picture.put_attachment(thbuffer, "th_" + filename) os.remove("th_" + filename) preview = self.get_thumbnail(filebody, filename, (1000, 1000)) picture.put_attachment(preview.read(), "prev_" + filename) os.remove("th_" + filename) picture.save() self.create_owner_creation_activity( picture, "publishes", "picture") self.send_files_to_contacts("pictures/contact/", fields = { "json": str(picture.toJson(localized=False)) }, files = [("picture", str(picture.path), thbuffer)]) logger.info("Picture %s successfuly posted." % filename) self.return_json(picture.toJson(), 201) else: self.return_failure("No picture posted.", 400)