[筆記] multipart/x-mixed-replace 即時更新資料
將 Content-Type 設為 `multipart/x-mixed-replace` 可以讓 server 動態更新圖片
Ex. 攝影機串流
```python
def gen():
while True:
frame = VideoCamera.get_camera().get_frame()
ret, jpeg = cv2.imencode('.jpg', frame)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + jpeg.tobytes() + b'\r\n\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
```
```html
<img src="/video_feed">
```
Reference:
- https://ithelp.ithome.com.tw/articles/10298661
2023-06-17 15:02:22
留言
Last fetch: --:--
現在還沒有留言!