Skip to content

MultipartFormTransformer corrupts files #119

@vplemyannik

Description

@vplemyannik

Version

4.5.14

Context

  /upload-file:
    post:
      operationId: uploadFile
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        200:
          description: OK

If you try to send binary file such as pdf, xlsx and etc , this file will be corrupted bacause MultipartFormTransformer read all body as string (UTF-8), binary file cotains not valid UTF-8 symbols that will be deleted , it seems to me that form must be parsed only on bytes level

https://github.com/eclipse-vertx/vertx-openapi/blob/4.5.21/src/main/java/io/vertx/openapi/validation/transformer/MultipartFormTransformer.java#L57

text.pdf

parsed_text.pdf

text.pdf - original file that i upload on server
parsed_text.pdf - file that i got on server side from validatedRequest

        val file = validatedRequest.body.jsonObject.getBuffer("file")
        
        File.createTempFile("parsed_text", ".pdf").writeBytes(file.bytes)
Image

I understand that i use vertx 4.5.14, but i looked at 5 version and seems to me there is the same problem

https://github.com/eclipse-vertx/vertx-openapi/blob/5.0.4/src/main/java/io/vertx/openapi/validation/analyser/MultipartFormAnalyser.java#L68

java 21.0.7 2025-04-15 LTS
Java(TM) SE Runtime Environment (build 21.0.7+8-LTS-245)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS-245, mixed mode, sharing)

Windows x86-64

Steps to reproduce

No response

Do you have a reproducer?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions