I want the user to be able to click a link like this:
<a href="/download?file=123">download</a>
Ask Pyramid 1.2.7 to process a 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
location /path/ { internal; root /opt/tmp; }
This all works, but instead of the browser showing the pdf download, the browser displays a bunch of PDF garbage.
How to customize Pyramid view to get browser to do the right thing?
source share