【问题标题】:Read data in chunks from large request_body从大型 request_body 中分块读取数据
【发布时间】:2020-06-09 14:51:07
【问题描述】:

我是龙卷风的新手。目前我想从帖子 request_body 中阅读。但是 post 请求中的数据很大,所以我想通过 Tornado 中的 stream_body_request 来实现它。但我无法实现它。如何分块读取这个“img_data”?

@stream_request_body
class MyReportPDF(BaseHandler):
async def post(self):
    data = escape.json_decode(self.get_body_argument('img_data'))#This data is an base_64_array
    for i in range(len(data)):
        # Clean the base_64 Image
        data[i].replace('data:image/jpeg;base64,', '')
        decode_image.append(base64.b64decode(data[i]))

【问题讨论】:

    标签: python-3.x request tornado chunks


    【解决方案1】:

    当您使用@stream_request_body 时,您的RequestHandler 类应该定义一个方法data_received,该方法将在数据进入时被调用。post 方法在收到所有数据后最后调用。

    请注意,目前无法将与参数相关的方法与@stream_request_body 一起使用;您需要解析data_received 中的数据。这意味着如果可能的话,您将希望构建您的API 以将图像作为普通HTTP PUT 接收,而不是包装在表单样式的POST 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-23
      • 2018-07-11
      • 2011-08-09
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2017-05-19
      相关资源
      最近更新 更多