1 回答
![?](http://img1.sycdn.imooc.com/54584ef20001deba02200220-100-100.jpg)
TA贡献1865条经验 获得超7个赞
看来你很困惑io.BytesIO。让我们看一些使用的示例BytesIO。
>>> from io import BytesIO
>>> inp_b = BytesIO(b'Hello World', )
>>> inp_b
<_io.BytesIO object at 0x7ff2a71ecb30>
>>> inp.read() # read the bytes stream for first time
b'Hello World'
>>> inp.read() # now it is positioned at the end so doesn't give anything.
b''
>>> inp.seek(0) # position it back to begin
>>> BytesIO.read(inp) # This is same as above and prints bytes stream
b'Hello World'
>>> inp.seek(0)
>>> inp.read(4) # Just read upto four bytes of stream.
>>> b'Hell'
read这应该能让您了解on 的工作原理BytesIO。我认为你需要做的是这个。
return send_file(
BytesIO(image.data),
mimetype='image/jpg',
as_attachment=True,
attachment_filename='f.jpg'
)
添加回答
举报