1👍
✅
As per @Pascal comment, I added Content-Length
and the downloads now work on mobile devices.
However it was not being downloaded with the filename I assign it in the view. Adding attachment
fixes this but I don’t want the attachment
to be present for desktop browsers. Hence the following is my final solution which works.
# I am using the decorator from http://code.google.com/p/minidetector/
@detect_mobile
def event_pdf(request, event_id, variant_id):
pdf = get_pdf()
response = HttpResponse(pdf, mimetype='application/pdf')
response['Content-Disposition'] = '%sfilename=foofile.pdf' %
request.mobile and 'attachment; ' or ''
response['Content-Length'] = len(pdf)
return response
Source:stackexchange.com