Replies: 1 comment
-
Thanks for bringing up this discussion. I would be skeptical to include a MultiPartParser in DJA as it is not standardized (yet) how it supposed to work. I am very supportive though to make the public API of DJA as easy extensible as possible so not standardized features can be experimented with in 3rdParty libraries. Therefore, feel free to open a PR. I would call the method rather |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently
rest_framework_json_api.parsers.JSONParser
only accepts stream-like objects as an input, intended for parsing incoming requests. This is fine and intended behavior for many use-cases.However, there are edge cases where json:api's specification is limited, e.g. when uploading files along with JSON data. This has been an open discussion for years (see json-api/json-api#246).
One (seemingly widely used) way to achieve this behavior is by sending the data as
multipart/form-data
and specifying adata
field with the JSON data as well as an additional field for files.This is then handled with a custom parser, inheriting functionality from
rest_framework.parsers.MultiPartParser
. This works in a similar fashion as theparse
method inJSONParser
, first running the request data through the parent parser and modifying it to fit the desired schema afterwards.The issue is that once you received the JSON data from
MultiPartParser
, there is no function on DRFJA to format that payload. You have to overwrite/copy-paste into your own method to access the parsing functionality after the initalrest_framework.parsers.JSONParser
call.Showing some code might explain it better:
This could be achieved by adding an extra method like
parse_json
, both making it public and using it from within the existingparser
method. Building custom parsers for DRFJA would be made a little easier this way. I would be happy to provide the PR.Any thoughts on this?
Here is an example of what a custom parser using this could look like:
Beta Was this translation helpful? Give feedback.
All reactions