Skip to content

Instantly share code, notes, and snippets.

@Joel-hanson
Last active July 31, 2020 10:33
Show Gist options
  • Save Joel-hanson/a7c3c5509822a0768175984a0fac2621 to your computer and use it in GitHub Desktop.
Save Joel-hanson/a7c3c5509822a0768175984a0fac2621 to your computer and use it in GitHub Desktop.
views for file upload for django rest framework
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from .serializers import UploadSerializer
# ViewSets define the view behavior.
class UploadViewSet(ViewSet):
serializer_class = UploadSerializer
def list(self, request):
return Response("GET API")
def create(self, request):
file_uploaded = request.FILES.get('file_uploaded')
content_type = file_uploaded.content_type
response = "POST API and you have uploaded a {} file".format(content_type)
return Response(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment