Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multipart/mixed POST #132

Open
ldanielburr opened this issue Aug 15, 2016 · 1 comment
Open

Support multipart/mixed POST #132

ldanielburr opened this issue Aug 15, 2016 · 1 comment

Comments

@ldanielburr
Copy link

There are some API services out there in the wild that require a content-type of "multipart/mixed", so that a POST may contain, for example, a JSON payload and a binary image.

treq inspects the kwargs for a POST, and if it finds "data", it sets the content-type to "application/x-www-form-urlencoded"; if it finds "files", it sets the content-type to "multipart/form-data". In order to support "multipart/mixed", treq could probably add a conditional check for "data and files", which if true would generate the appropriate request header and body.

@twm
Copy link
Contributor

twm commented Oct 19, 2020

Right now data + files does have meaning: data must be a dict or sequence of (param name, value) tuples. These are added to the multipart/form-data request body before the files (they populate the fields parameter of treq.multipart.MultiPartProducer along with any other files).

To craft a multipart/mixed body I think you'd do best to create an IBodyProducer implementation that produces the MIME boilerplate, the JSON part, and then delegates to MultiPartProducer. Such an implementation would be a reasonable addition to treq.

It is a bit confusing that data functions as both the "I want to fully control the request body" and a convenience wrapper for application/www-form-urlencoded and multipart/form-data key/value items. I suppose that design error was inherited from requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants