我想制作一个视频共享网站(如 youtube),但我无法发送大型视频文件。当我尝试访问我的网站并加载视频时,我的网站开始发送文件,但 Firefox 在一段时间后停止接收数据。我知道有些网站会将大视频分成几部分并单独发送每个部分,但我不知道如何使用 Flask 做到这一点。
这是我目前的代码:
import flask
from mimetypes import guess_type
app = flask.Flask(__name__)
def rf(path, mode='rb'):
file = open(path, mode)
data = file.read()
file.close()
return data
@app.route('/')
def index():
return flask.Response(rf('./root/index.html'))
@app.route('/favicon.ico')
def favicon():
return flask.Response(rf('./root/favicon.png'))
@app.route('/<path:pth>')
def autopath(pth):
if not isfile('./root/' + pth):
pth += '.html'
if not isfile('./root/' + pth):
return flask.Response("ERR: 404", status=404)
mime = guess_type(pth, False)
if mime[0] == None:
mime = ('text/text')
return flask.Response(rf('./root/' + pth), mimetype=mime[0])
if __name__ == '__main__':
app.run('localhost', 80)
flask 中是否有允许分块发送大文件的功能?