how to set uploadhandlers on a per-request basis using django rest framework?

It seems like you are not assigning the upload handler in the right way

from django.core.files.uploadhandler import TemporaryFileUploadHandler
from rest_framework import viewsets


class MyUploadViewSet(viewsets.ModelViewSet):
    # your view class attributes goes here....
    def initialize_request(self, request, *args, **kwargs):
        request.upload_handlers = [TemporaryFileUploadHandler(request)] # initialization goes here
        return super().initialize_request(request, *args, **kwargs)

Note

This will work as-is in all DRF class based views

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top