<s> import base64 <EOL> from django . http import Http404 , HttpResponse <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . views . decorators . cache import cache_control <EOL> import mimetypes <EOL> from database_files . models import File <EOL> import os <EOL> @ cache_control ( max_age = <NUM_LIT> ) <EOL> def serve ( request , name ) : <EOL> pk , file_ext = os . path . splitext ( name ) <EOL> try : <EOL> pk = int ( pk ) <EOL> except ValueError : <EOL> raise Http404 ( '<STR_LIT>' ) <EOL> f = get_object_or_404 ( File , pk = pk ) <EOL> mimetype = mimetypes . guess_type ( name ) [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> response = HttpResponse ( base64 . b64decode ( f . content ) , mimetype = mimetype ) <EOL> response [ '<STR_LIT>' ] = f . size <EOL> return response </s>
