Use djangos fileresponse

This commit is contained in:
Jake Howard 2016-09-12 21:32:44 +01:00
parent 7375610b2a
commit 40f71ba5f1
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,6 +1,6 @@
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.http import HttpResponse from django.http import FileResponse as BaseFileResponse
from .models import SharedFile, FileToken from .models import SharedFile, FileToken
import mimetypes import mimetypes
from django.utils import timezone from django.utils import timezone
@ -21,7 +21,7 @@ class SharedFileDetails(TemplateView):
def FileResponse(file): def FileResponse(file):
response = HttpResponse(file.file) response = BaseFileResponse(file.file)
response['Content-Type'] = mimetypes.guess_type(file.get_original_filename())[0] response['Content-Type'] = mimetypes.guess_type(file.get_original_filename())[0]
response['Content-Disposition'] = 'attachment; filename="{0}"'.format(file.get_original_filename()) response['Content-Disposition'] = 'attachment; filename="{0}"'.format(file.get_original_filename())
return response return response