0

I am trying to construct a python request based on swagger.json schema. It mentioned multipart/form data and I did some research. And now the remaining issue is about type "array", not sure how to do it. Below is swagger.json schema.

            "requestBody": {
                "required": true,
                "content": {
                    "multipart/form-data": {
                        "schema": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "name": {
                                    "type": "string"
                                },
                                "file": {
                                    "items": {
                                        "type": "string",
                                        "format": "binary"
                                    },
                                    "type": "array"
                                }
                            },
                            "required": [
                                "id",
                                "name",
                                "file"
                            ]
                        }
                    }
                }
            }

I found files parameter in python requests module could do the multiform(How to send a "multipart/form-data" with requests in python?), but I don't know how to do the 'file' part which is an array here...if it is not array, just one object. I will go with 'file': ('testfile', open('testfile', 'rb') current the UI side has not been deployed, so I cannot test. so could anyone help here? Thanks

    data = {
            'id' : test_id,
            'name' : test_name,
            'file': []
            }
nathan
  • 754
  • 1
  • 10
  • 24
  • Does these links answer your question? -- [Can I post an array of files using form/multipart in Python?](https://stackoverflow.com/q/54631820/113116), [Is there a way of sending a multipart/form-data array using Python requests?](https://stackoverflow.com/a/74389385/113116), [Uploading multiple files in a single request using Python requests module](https://stackoverflow.com/q/18179345/113116) – Helen Dec 08 '22 at 09:47

0 Answers0