django-dbfilestorage-old/dbfilestorage/views.py
Tyrel Souza 4b7738c0f2
Python3 and Django 1.11 upgrade (#40)
* starting py3 upgrade

* b64 not base64

* more progress, some more future things, and encoding

* tox

* update circle.yml

* that version doesnt exist yet, oops

* install?

* sigh

* Docker me?

* update readme, requirements

* fix for python3

* python35

* morgan remediations

* does this work?

* how about this?

* one more time

* no blank lines?

* revert a bit

* add future imports
2018-03-01 15:32:02 -05:00

27 lines
773 B
Python

from __future__ import absolute_import, print_function, unicode_literals
import base64
from django.http import HttpResponse, Http404
from django.db.models import Q
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
"""
dbf = get_object_or_404(DBFile, name=name)
response = HttpResponse(
base64.b64decode(dbf.b64),
content_type=dbf.content_type)
response['Content-Disposition'] = 'attachment; filename="{}"'.format(
dbf.name)
return response