Commits

Matthew Schinckel  committed bfd4d59

Change the order in which the serializer works, to prevent an issue
where we could not read from the request stream.

  • Participants
  • Parent commits aad4539

Comments (0)

Files changed (1)

File rest_api/serializers/__init__.py

 deserializers = {
     'application/json': json,
     'application/xml': xml,
-    'application/x-www-form-urlencoded': post
+    'application/x-www-form-urlencoded': post,
+    'multipart/form-data': post,
 }
 
 def remove_invalid_chars(data):
     # Need to do this before accessing raw_post_data!
     request._load_post_and_files()
     
-    # Inspect the data, in case the headers are incorrect.
-    serializer = inspect_content(request.raw_post_data)
-    if serializer:
-        raw_post_data = remove_invalid_chars(request.raw_post_data)
-        return serializer.deserialize(raw_post_data)
-        
     content_type = request.META.get('CONTENT_TYPE')
     if content_type and ";" in content_type:
         content_type = content_type.split(';')[0]
             return serializer.deserialize(request.POST)
         return serializer.deserialize(QueryDict(request.raw_post_data))
     
+    if not serializer:
+        # Inspect the data, in case the headers are incorrect.
+        serializer = inspect_content(request.raw_post_data)
+    if serializer:
+        raw_post_data = remove_invalid_chars(request.raw_post_data)
+        return serializer.deserialize(raw_post_data)
+    
     if request.method in ["POST", "PUT"]:
         raw_post_data = request.raw_post_data