channels icon indicating copy to clipboard operation
channels copied to clipboard

Channels Error upload Handler

Open ahmadhaidarahmad opened this issue 8 years ago • 2 comments

Hi, I'm using django channels for a real time notifications system, and I'm using also normal rest apis in my project. The problem is when I'm calling a normal post api that uploads files to the server I'm getting this error:

     File "/usr/lib/python2.7/dist-packages/django/http/request.py", line 248, in upload_handlers
     raise AttributeError("You cannot set the upload handlers after the upload has been processed.")
     AttributeError: You cannot set the upload handlers after the upload has been processed.

The Api function is:

@api_view(['POST'])
def AddGroup(request):
    
    """
    
    Add New Room inside Group
    
    """
    try:
        
        data = request.POST
        groupname = data.get('groupname')
        groupdescription = data.get('groupdescription')
        privacyid = data.get('privacy_id')
        #privacyid = 1
        grouptitle = data.get('grouptitle')
        image = image = request.FILES['image'] #data.get('image')
        user = request.user
        group = Group.objects.create(creator = user, groupname = groupname, title = grouptitle,
                                        groupadmin = user, adminhelper = user,image = image, createddate =   dattetime.now(),
                                        description = groupdescription, privacyid = privacyid, isactive = 1,
                                       )
etc ...

And how can i let normal requests run through django for some cases like this not through channels all the time. Any help please ??

ahmadhaidarahmad avatar Dec 19 '17 07:12 ahmadhaidarahmad

Hi,

You can run WSGI and ASGI servers simultaneously http://channels.readthedocs.io/en/latest/deploying.html#running-asgi-alongside-wsgi

To fix file handler error if it is actually a channels bug we need a fully reproducible example.

Regards, Artem.

proofit404 avatar Dec 19 '17 08:12 proofit404

Problem is that channels trying to handle POST and FILES here https://github.com/django/channels/blob/1.x/channels/handler.py#L161-L165 As workaround you can send PUT request instead POST to avoid processing inside channels.

noroot avatar Mar 09 '18 15:03 noroot