Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rg3915/e665b81fa56a2ba24dfd870a705b31be to your computer and use it in GitHub Desktop.
Save rg3915/e665b81fa56a2ba24dfd870a705b31be 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