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

MultiPartBody: Impossible to add multiple Body Parts with the same name #6261

Open
romanett opened this issue Mar 12, 2025 · 0 comments
Open
Labels
Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

Comments

@romanett
Copy link

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

I am using an existing API with the Atteached API Spec.

It expects a multipart body with an array of files:

e.g swagger Editor lets you paste multiple files:

Image

However the KIOTA Multipart body uses a dictionary based on the Part name, so this does not allow you to create such a body:

            body.AddOrReplacePart<byte[]>("files", "text/plain", file, "test.txt");
            body.AddOrReplacePart<byte[]>("files", "text/plain", file, "test2.txt");

 if(!_parts.TryAdd(partName, value))
 {
     _parts[partName] = value;
 }

This creates such a request:

RequestRaw:

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test.txt"

Test

--d11b4f38539b40fbb6a300dfddcede33--

However I want to create such an request:

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test.txt"

Test

--d11b4f38539b40fbb6a300dfddcede33
Content-Type: text/plain
Content-Disposition: form-data; name="files"; filename="test2.txt"

Test2

--d11b4f38539b40fbb6a300dfddcede33--

Expected behavior

Be able to create a multipart body with multiple elements with the same name.

How to reproduce

Generate client with attached API spec.

Try to add multiple files

Open API description file


openapi: 3.0.1
info:
  title: Test
  version: 1.0.0.0
paths:
  /v6/mailbox/messages:
    put:
      summary: Insert a message into a Mailbox
      description: |
        ## This endpoint inserts a message into the specified mailbox.
        **Returns** an object with ids for the newly created message
      operationId: putMessageV6
      requestBody:

        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CreateMessage'
            encoding:
              files:
                contentType: application/octet-stream
      responses:
        '200':
          description: |
            The id of the created message is returned.
components:
  schemas:
    CreateMessage:
      type: object
      properties:
        files:
          type: array
          items:
            type: string
            description: |-
              files to upload.

              ### curl example:

              ```-F 'files=@sample.txt;type=text/plain'```
            format: binary
      description: |
        ### curl example:
        ```-F 'files=@sample.txt;type=text/plain;'```

Kiota Version

1.23.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Configuration

OS: Windows 10
Architecture x64
.Net 9

Debug output

Click to expand log ```
</details>


### Other information

Repro project will follow
@romanett romanett added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Mar 12, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Mar 12, 2025
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
Status: Needs Triage 🔍
Development

No branches or pull requests

1 participant