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

Automatically json.dumps when sending a dict in a multipart request #93

Open
maingoh opened this issue Oct 21, 2020 · 2 comments · May be fixed by #100
Open

Automatically json.dumps when sending a dict in a multipart request #93

maingoh opened this issue Oct 21, 2020 · 2 comments · May be fixed by #100

Comments

@maingoh
Copy link
Contributor

maingoh commented Oct 21, 2020

When sending a multipart request (with files) if we want to attach a metadata field or any field that is nested, currently the user should json.dumps it or it might be ignored by the server (hard to debug).
We should probably improve

data = self.dump_json_for_multipart(data)
so that the user can do:

Example:

client.http_helper.post(files={'file': open('file', 'rb')}, data={'metadata': {'foo': 'bar'}}, content_type=''multipart/mixed'')

Instead of:

client.http_helper.post(files={'file': open('file', 'rb')}, data={'metadata': json.dumps({'foo': 'bar'})}, content_type=''multipart/mixed'')
@maingoh
Copy link
Contributor Author

maingoh commented Feb 26, 2021

This is also the case when trying to post a file using ImageInput with a bbox (or other nested field). If the encoding is binary we should automatically dumps the bbox dict.

@qtreh
Copy link

qtreh commented Apr 9, 2021

data = self.dump_json_for_multipart(data) converts fields to keys and values such that:

http_helper.dump_json_for_multipart({'level_0': {'level_1': {'level_2': "niveau 2"}}, 'level_0_bis': 'niveau 0'})
# => returns {'level_0.level_1.level_2': 'niveau 2', 'level_0_bis': 'niveau 0'}

If we have a bbox in input, it will separate the coordinates in 4 keys: 'image.input.bbox.xmin': 0.25, 'image.input.bbox.xmax': 0.65, ... this is not good, and it fails anyway because floats make Vulcan fail.

I tried dumping the data and files to stringified json, but it doesn't work if the image has a binary as source instead of a url.

The best way to solve this is still to convert precise jsons we want to pass, like the bbox. So I modified the ImageInput.get_input() method to convert the bbox in those cases.

@qtreh qtreh linked a pull request Apr 12, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants