2018-03-01 20:32:02 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
|
|
|
import base64
|
|
|
|
|
2017-01-20 19:38:41 +00:00
|
|
|
from django.http import HttpResponse, Http404
|
|
|
|
from django.db.models import Q
|
2016-12-08 03:50:48 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
|
|
|
|
from .models import DBFile
|
|
|
|
|
|
|
|
|
|
|
|
def show_file(request, name):
|
|
|
|
"""
|
|
|
|
Get the file object referenced by :name:
|
|
|
|
Render the decoded base64 representation of the file,
|
|
|
|
applying the content_type (or closest representation)
|
|
|
|
|
|
|
|
:return HttpResponse: Rendered file
|
|
|
|
"""
|
2017-01-27 20:52:02 +00:00
|
|
|
dbf = get_object_or_404(DBFile, name=name)
|
|
|
|
response = HttpResponse(
|
2018-03-01 20:32:02 +00:00
|
|
|
base64.b64decode(dbf.b64),
|
2017-01-27 20:52:02 +00:00
|
|
|
content_type=dbf.content_type)
|
|
|
|
response['Content-Disposition'] = 'attachment; filename="{}"'.format(
|
|
|
|
dbf.name)
|
|
|
|
return response
|