How do I display the image from a flask send_file ajax response
HTML file
<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;
}
});
});
flask
@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")