如何显示烧瓶的send_file ajax响应中的图像
HTML文件
<button class="button" id="start">Start</button>
<script>
//start button click event
$('#start').click(function() {
$.ajax({
url: 'http://127.0.0.1:5000/capture',
type: 'GET',
contentType: "image/jpg",
success: function(result) {
document.getElementById('frame').src = 'data:image/jpg,' + result;
}
});
});
烧瓶
@app.route('/capture')
def capture_api():
...
image_binary = img.read()
return send_file(io.BytesIO(image_binary),
mimetype='image/jpeg',
as_attachment=True,
attachment_filename='%s.jpg' % "capture")
问题出在后端和前端的编码上。
在烧瓶
image = b64encode(image_binary).decode("utf-8")
return jsonify({'status': True, 'image': image})
html
document.getElementById('frame').src = 'data:;base64,' + result['image'];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句