question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

multipart/form-data request is splitting up data field by field

See original GitHub issue

Hello,

I’m using openapi-generator maven plugin to generate the client side java classes and interfaces for a third-party API. Generator version: 5.3.1 and FEIGN library to generate the client side.

API: requestBody: content: multipart/form-data: schema: $ref: '.domain#/components/schemas/Document' encoding: metadata: contentType: application/json style: form Domain: Document: type: object properties: metadata: $ref: '#/components/schemas/Metadata' document: type: string description: Array of bytes representing the content of the document format: binary

When I’m sending the request the metadata is split field by field instead of having it sent over as JSON.

` Content-Disposition: form-data; name=“validUntilRevoked” Content-Type: text/plain; charset=UTF-8

true Content-Disposition: form-data; name=“value” Content-Type: text/plain; charset=UTF-8

lorem ipsum Content-Disposition: form-data; name=“extRef” Content-Type: text/plain; charset=UTF-8

abc Content-Disposition: form-data; name=“issueDate” Content-Type: text/plain; charset=UTF-8 1992-10-12`

I’m expecting to be sent over in this format: `Content-Disposition: form-data; name=“metadata” Content-Type: text/plain; charset=UTF-8

{“evidenceType”:“<string>”,“ext_ref”:“<string>”,“issueDate”:“<string>”,“validUntilRevoked”:“<boolean>”} ` Do you have any idea if this is a bug on the openapi generatoror in the feign client?

Any suggestions will be appreciated.

Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Breinacommented, Apr 11, 2022

You can’t set both content types myltipart to upload files and application/json to upload data in same request.

If it is not already supported, I feel like it should in any case:

Each part MAY have an (optional) “Content-Type” header field, which defaults to “text/plain”. If the contents of a file are to be sent, the file data SHOULD be labeled with an appropriate media type, if known, or “application/octet-stream”.

https://datatracker.ietf.org/doc/html/rfc7578#section-4.4

0reactions
bogdancondescucommented, Apr 19, 2022

I found the way to solve it, modifying the encoder of Feign client and adding JsonFormWriter as first writer. apiClient.getFeignBuilder().encoder(new SpringFormEncoder() {{ var processor = (MultipartFormContentProcessor) getContentProcessor(ContentType.MULTIPART); processor.addFirstWriter(jsonFormWriter); processor.addFirstWriter(new SpringSingleMultipartFileWriter()); processor.addFirstWriter(new SpringManyMultipartFilesWriter()); }});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can one http mutlipart request split up the file in multiple parts?
Multipart file does not mean that a file is split into multiple parts, it means that the request is split into multiple parts....
Read more >
Multipart/form-data content type - Software AG Documentation
A multipart/form-data request body contains a series of parts separated by a boundary delimiter, constructed using Carriage Return Line Feed (CRLF), "--", and ......
Read more >
File Uploads - Django documentation
When Django handles a file upload, the file data ends up placed in request.FILES (for more on the request object see the documentation...
Read more >
Multipart formposts - Everything curl
A multipart formpost is what an HTTP client sends when an HTML form is submitted with enctype set to "multipart/form-data". It is an...
Read more >
Multipart (Form Data) Format - MuleSoft Documentation
This example serves as input to separate DataWeave scripts. shows a raw multipart/form-data payload with a 34b21 boundary consisting of 3 parts:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found