0

I want to make a video sharing website (like youtube) but i am having trouble with sending a large video file. When I try to go to my website and load in the video, my website starts sending the file but firefox stops receiving data after some time. I know some websites split big videos into parts and send each part seperatly but i don't know how to do that with flask.

here is my code so far:

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)

Is there a function in flask that allows sending big files in chunks?

BIT-REAPER
  • 40
  • 7

0 Answers0