【问题标题】:Enconding of file sent using FLASK function send_file使用 FLASK 函数 send_file 发送的文件的编码
【发布时间】:2020-11-11 19:40:50
【问题描述】:

当我们使用flask函数send_file时,在REST body上使用mimetype image/jpeg发送的文件的实际编码是什么?是否可以使用 base64 编码发送文件?

代码行:

send_file("logo.jpg", mimetype='image/jpeg')

【问题讨论】:

    标签: python rest flask


    【解决方案1】:

    它在网络上以二进制形式发送,例如HTTP 响应将是

    200 OK
    Content-type: image/jpeg
    Content-length: 1234
    
    ����JFIF��
              ExifMM*
    $���1�2��i��%�OnePlusONEPLUS A6013
    

    等等

    如果您的应用需要,您可以手动对数据进行 base64 编码。

    【讨论】:

    • 如何手动对jpg图像进行base64编码并使用send_file函数发送?
    • 手动编码图像时不能使用send_file()。您会读取图像,对其进行编码,然后将其作为常规响应发送。
    猜你喜欢
    • 2017-09-24
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 2019-05-13
    • 2023-01-27
    • 2021-07-04
    • 2020-03-28
    相关资源
    最近更新 更多