gkuhn1 / django-admin-multiupload

Multi file upload for django-admin app
71 stars 65 forks source link

Extra content_type - Unexpected token < in JSON at position 0 #26

Closed python-force closed 7 years ago

python-force commented 7 years ago

I found out why the upload was failing on 1.11.4

Error is "SyntaxError: Unexpected token < in JSON at position 0" because response is not a json but it is surrounded by <html><body>

On the line 220 here and line 236 it makes no sense, you have not used content_type = "text/html", I have removed it and it started working.

https://github.com/gkuhn1/django-admin-multiupload/blob/master/multiupload/admin.py

            `content_type = "application/json"
            # QUIRK HERE
            # in jQuey uploader, when it falls back to uploading
            # using iFrames
            # the response content type has to be text/html
            # if json will be send, error will occur
            # if iframe is sending the request, it's headers are
            # a little different compared
            # to the jQuery ajax request
            # they have different set of HTTP_ACCEPT values
            # so if the text/html is present, file was uploaded
            # using jFrame because
            # that value is not in the set when uploaded by XHR
            if "text/html" in request.META["HTTP_ACCEPT"]:
                content_type = "text/html"
            content_type = "text/html"`
gkuhn1 commented 7 years ago

Nice, this issue was fixed in PR #25. Thanks