我想在Flask支持的网站上使用循环播放的视频.显然,Chrome不会循环播放视频unless it was streamed with an HTTP 206 code being returned.但是,Flask始终使用HTTP 200返回此静态文件.如何从我的Flask项目(作为记录托管在Heroku中)中流式传输静态内容,以使视频正确循环在Chrome中?
解决方法:
在提供视频文件时遇到了同样的问题,并且通过研究Werkzeug的源代码找到了解决方案.我通过在send_from_directory函数中添加conditional = True标志来解决此问题,如下所示:
@app.route('/uploads/<filename>')
def uploaded_file(filename):
"""Endpoint to serve uploaded videos
Use `conditional=True` in order to support range requests necessary for
seeking videos.
"""
return send_from_directory(app.config['UPLOAD_FOLDER'], filename,
conditional=True)