1
我正在使用flask服務器從FTP服務器提取數據併爲其提供服務(視頻)。 相機在向遠程FTP服務器發送新視頻時向服務器發送「確定」。 Flask服務器從FTP中獲取新視頻。 我需要的是當燒瓶運行get_video函數時,也刷新html的內容,以便用戶將看到新的視頻。在Flask服務器中自動重新加載FTP內容
請注意,相機和用戶是不同的客戶端,它們都連接到同一個Flask服務器。
from flask import Flask, Response, request, render_template, g, redirect
import ftplib
app = Flask(__name__)
def get_video():
session = ftplib.FTP("****", "*****", "****")
session.retrbinary("RETR try.mp4", open("static/sc.mp4", "wb+").write)
@app.route('/')
def hello():
get_video()
return '''
<!doctype html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<title>Files</title>
<h1>VIDEO</h1>
<video width="320" height="240" id="VideoWindow" controls>
<source src="static/sc.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</form>
<form action="/shoot_request">
<input type="submit" name="shoot" value="GetNew"/>
</form>
<script type='text/javascript'>
$(document).ready(function() {
setInterval(function() {
$('#VideoWindow').load(window.location.href + '#VideoWindow');
}, 5000);
});
</script>
'''
@app.after_request # This did not work
def add_header(response):
response.cache_control.max_age = 10
return response