def post(self): intro = self.args["intro"] data = self.args["data"].split(',') q = qiniu.Auth(ACCESS_KEY, SECRET_KEY) token = q.upload_token(BUCKET_PHOTO) key = str(time.time())+':'+str(self.current_user.id) ret, info = put_data(token, key, urlsafe_base64_decode(data[1]), mime_type=data[0][5:-7], check_crc=True) if info.status_code == 200: self.session.add(models.Photo(img_url=key, intro=intro, author_id=self.current_user.id)) self.session.commit() return self.send_success() return self.send_error()
def unmarshal_up_token(self, up_token): token = up_token.split(':') if (len(token) != 3): raise ValueError('invalid up_token') ak = token[0] policy = compat.json.loads(compat.s(utils.urlsafe_base64_decode(token[2]))) scope = policy["scope"] bucket = scope if (':' in scope): bucket = scope.split(':')[0] return ak, bucket