【发布时间】:2020-02-06 12:29:12
【问题描述】:
我有一个烧瓶应用程序,它将 mp4 文件存储在本地目录中,并将路径保存在我的数据库中。我可以访问烧瓶提供的文件用户send_file 并下载,但是当我将路径传递给视频标签时,它没有被显示。见以下代码:
保存视频文件:works fine as expected
@app.route('/', methods=['GET', 'POST'])
def index():
form = VideoPicForm()
if form.validate_on_submit():
if form.vid.name not in request.files:
flash('No video part specified')
return redirect(url_for('index'))
file = request.files[form.vid.name]
if file.filename == '':
flash('No file selected for uploading')
return redirect(url_for('index'))
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filepath = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
video= VideosFiles(description=form.description.data, vidpath=filepath)
db.session.add(video)
db.session.commit()
flash('video uploaded successfully...')
return redirect(url_for('index'))
return render_template('index.html', title='Home', form=form)
从模板访问:```文件未呈现``
@app.route('/display')
def display():
file_data= VideosFiles.query.filter_by(id=1).first()
video= file_data.vidpath
return render_template('display.html', title='Videos', video=video)
在模板中:
<video width="320" height="240" controls>
<source src="{{video}}" type="video/mp4" />
</video>
但是当我使用send_file 下载时,视频会立即下载:
@app.route('/download')
def download():
file_data= VideosFiles.query.filter_by(id=1).first()
video= file_data.vidpath
return send_file(video, as_attachment=True)
我是否遗漏了导致视频未在模板中呈现的任何内容?
【问题讨论】: