Skip to content

Instantly share code, notes, and snippets.

@antonioccneto
Created December 19, 2021 00:56
Show Gist options
  • Save antonioccneto/086ae0f9dca7db0cebe2256507d26844 to your computer and use it in GitHub Desktop.
Save antonioccneto/086ae0f9dca7db0cebe2256507d26844 to your computer and use it in GitHub Desktop.
Função simples pra testar download de arquivo no DRF
# viewsets.py
from rest_framework.decorators import api_view, permission_classes
from django.http import FileResponse
from django.shortcuts import get_object_or_404
@api_view(['GET'])
@permission_classes((IsAuthenticated,))
def download(file):
""" Função simples para Download de Arquivo """
arquivo = file
obj = get_object_or_404(SeuModel, arquivo=arquivo)
return FileResponse(obj.arquivo)
# urls.py
from minhaApp.api.viewsets import download
...
path('media/<str:file>', download, name='download'),
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment