How do I serve this video file for download using pyramid FileResponse
<p>Please what am i missing. I keep on getting internal server error in browser when I want to serve this video file that has been downloaded on disk.
here is my code: The view function</p>

<pre><code>@view_config(name='download_video')
def dl(request):
    url = request.params.get('url')
    camefrom = request.params.get('came_from')
    path_dir = request.registry.settings['app.download_path']
    result= save_to_disk(url, path_dir)
    if result:
        filename = result['filename']
        filepath = os.path.abspath(os.path.join(path_dir,filename))
        file_exists = os.path.exists(filepath)
        if file_exists:
            res = FileResponse(filepath,content_type='video/mp4')
            res.headers['Content-Length'] = os.path.getsize(filepath)
            res.headers['Content-Disposition'] = 'attachment;filename=%s'%filename
            return res
    request.session.flash(_("Error downloading video, please check your network","danger"))
    return HTTPFound(location=camefrom)
</code></pre>

<p>The template</p>

<pre><code>&lt;a tal:attributes="href api.url(api.root, '@@download_video', query={'came_from': request.url,'url':context.video_url})" class="btn"&gt;Download&lt;/a&gt;
</code></pre>

<p>The video downloads and I can see it in the folder but I keep on getting internal server error without tracebacks on browser</p>

<p>My app depends on Kotti cms</p>