#28678: Multipart parser should decode those JSON parts that are flagged as such
-------------------------------------+-------------------------------------
Reporter: Facundo Batista | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: HTTP handling | Version: 1.11
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by timtaiwanliim):
These 3 issues are related.
[1] https://code.djangoproject.com/ticket/21442
[2] https://code.djangoproject.com/ticket/28678
[3] https://github.com/encode/django-rest-framework/issues/4881
[1] is the overall tracker for this issue, desires to create a
configurable parser. Opened 9 years ago.
[3] describes the desired behavior with example. Opened 5 years ago.
[2] has a proposed fix (credit: Facundo Batista). The fix is simple and
worked well when I tried it. Opened 5 years ago.
Surely a configurable parser [1] is a good goal to pursue. But if it
takes 9 years before anything happens, perhaps we can take [2]? It is
not configurable, but it works well.
re: a case for multipart parser that can handle json parts
I have an api that takes some json input, plus 2 optional image files.
With json parser, I cannot easily include image files (base64 works, but
clumsy for modest size images).
Multipart parser allows me to send the json input plus images in 1
call. But all the data parts are treated as text (str). One of the
data field is a dict (eg. { "x": 7, "y": 5 }).
If I use json parser, it is an dict (good).
If I use multipart parser, it becomes a str (bad; desired to get a
dict).
> it could be backwards incompatible (data could now be a different type
in request.POST, correct?).
Not so.
Only if the parts have http header "content-type: application/json",
then those parts become dict (the desired type; currently of str
type).
For the parts (of multiparts) that do not have "content-type" header,
the results remain as str type.
(see [3] for an example of the "content-type" of the parts)
--
Ticket URL: <https://code.djangoproject.com/ticket/28678#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018295c87ad2-f0ecb08b-ce71-4fc3-9467-5f7cc03b6b5f-000000%40eu-central-1.amazonses.com.