Use StreamingHttpResponse to server documents

This commit is contained in:
Dan Braghis 2015-02-12 11:39:31 +00:00
parent f36836bc48
commit 918f286eea

View file

@ -1,6 +1,6 @@
from django.shortcuts import get_object_or_404
from django.http import HttpResponse
from wsgiref.util import FileWrapper
from django.http import StreamingHttpResponse
from wagtail.wagtaildocs.models import Document, document_served
@ -8,7 +8,7 @@ from wagtail.wagtaildocs.models import Document, document_served
def serve(request, document_id, document_filename):
doc = get_object_or_404(Document, id=document_id)
wrapper = FileWrapper(doc.file)
response = HttpResponse(wrapper, content_type='application/octet-stream')
response = StreamingHttpResponse(wrapper, content_type='application/octet-stream')
# TODO: strip out weird characters like semicolons from the filename
# (there doesn't seem to be an official way of escaping them)