У меня есть приложение flask, которое хранит файлы mp4 в локальном каталоге и сохраняет путь в моей базе данных. Я могу получить доступ к файлу пользователя send_file
, предоставленному flask, и загрузить его, но когда я передаю путь к тегу видео, он не отображается. См. Код ниже:
Сохранение видеофайла: 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)
Мне не хватает чего-либо, из-за чего видео не отображается в шаблоне?