1

I have a web application which displays pdf's in an IFrame. I recently made a change to start serving up the PDF using Django instead of allowing Apache to serve the PDF. Initially, I used the FileWrapper approach to return the file. This worked fine on all browsers except for IE 8 which crashed (maybe other versions of IE, didn't test).

I figured out how to fix this but it was a bit of a pain to figure out so I am posting the answer here.

Maurice Flanagan
  • 5,179
  • 3
  • 30
  • 37

1 Answers1

3

The solution was to use mod_xsendfile as suggested in this post with the following tweaks:

mimeType,_ = mimetypes.guess_type(filePath)
response = django.http.HttpResponse(mimetype = mimeType)
response['Accept-Ranges'] = 'bytes'
response['X-Sendfile'] = filePath
return response

In addition to working correctly with IE / iframes, it allows the file download to be resumable.

Community
  • 1
  • 1
Maurice Flanagan
  • 5,179
  • 3
  • 30
  • 37