-
Notifications
You must be signed in to change notification settings - Fork 48
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Multipart support for the requests to server #96
Comments
It sounds like you're on the right track; I'd add a new condition in here to hande Off the top of my head, it might look something like this: def _request_handle_body(self, data):
# this is assuming a new class, MultipartFormData, is defined that wraps the values expected by requests
# and can return the correctly-formatted tuple
if isinstance(data, MultipartFormData) and "multipart/form-data" in self.requestBody.content:
# some validation to ensure that incoming field names match those in the spec
self._request.files = data.serialized
elif "application/json" in self.requestBody.content:
# existing code I'd expect to use it like this: spec.call_multipartOperation(
data=MultipartFormData(
MultipartFormDataFile("field-name", "filename", file_object, "content/type"),
MultipartFormDataFile("field-name", "filename2", file_object_2, "content/type"),
),
) Those aren't hard requirements though, just how I'd do it; if you have other ideas, I'd be happy to hear them. Feel free to open a draft PR if you'd like to collaborate more directly. |
Thank you for the quick response! For now I check the properties in the schema in the self.requestBody.content['multipart/form-data'] for the format field. Other variant is to pass one more parameter to _request_handle_body - with files. When I have something working I will make a PR and I will iterate from there, |
Hi! For now there it supports to pass only dictionary with the format - { "field name": file_obj }. For the implementation - I choose a separate structure files as so there is no need to decide what field is a file and what not. I will be happy to become a feedback for the implementation! |
Hi,
I need to make multipart requests to server and I'm trying to add this feature to the code.
For now I think to add files to _request.files and add them to _request.files and the rest will add to the fields.
At the moment it's work in progress.
Do you have any tips or any requirement to the implementation?
I would love to see this feature in this library.
PS: Also I think that it would be great when a NotImplementedError is raised there would be also a message.
The text was updated successfully, but these errors were encountered: