Last active
July 31, 2020 10:33
-
-
Save Joel-hanson/a7c3c5509822a0768175984a0fac2621 to your computer and use it in GitHub Desktop.
views for file upload for django rest framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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