I want a user to be able to click a link like this:
<a href="/download?file=123">download</a>
Have a Pyramid 1.2.7 app handle the view like this
@view_config(route_name='download')
def download(request):
file_id = request.GET['file']
filename = get_filename(file_id)
headers = request.response.headers
headers['Content-Description'] = 'File Transfer'
headers['Content-Type'] = 'application/force-download'
headers['Accept-Ranges'] = 'bytes'
headers['X-Accel-Redirect'] = ("/path/" + filename + ".pdf")
return request.response
And my nginx configuration looks like this
location /path/ {
internal;
root /opt/tmp;
}
This all works but instead of the browser showing a pdf has download, the browser displays a bunch of PDF garbage.
How do I setup my Pyramid view to get the browser to do the right thing?