Skip to content

Support mixed multipart/form‑data text fields and file parts in one interaction #499

Open
@jakubpawlik-identt

Description

@jakubpawlik-identt

Hi! I’m trying to write a Pact test in pact-python v3 where my consumer sends a single multipart/form-data request containing:

  • JSON field (text)
  • binary file (video.mp4)

However, the Pact on the provider side never sees the JSON field, it only sees the file part. As @YOU54F suggested that the core Pact Reference implementation may not currently support mixing JSON (or other form fields) with file parts in one multipart/form-data message.

Expected Behavior
The Pact should generate a multipart/form-data request that includes both:

  • A file part named file containing the contents of video.mp4.
  • A form field named text with the JSON/string value text_value.

Actual Behavior
Only the file part is received by the mock server.

Questions

  1. Does the Pact Reference core support multipart requests with mixed JSON (or form) fields and file parts?
  2. If not, is there a recommended workaround or timeline for adding this feature?
  3. Would a new RFC be required to track and implement this functionality?

Thanks in advance, Jakub


I started here: pact-foundation/pact-python#1069

Hello guys!
Maybe an observation from my side: it is not clear for my side if multipart/form-data is supported in v3--> can we prepare an interaction using with_multipart_file and something else ?
I don't know how to attach a body as part in my multipart.
See this test for instance using only with_multipart_file
Any clue ?
Thanks!!
Olivier

Originally posted by @opicaud in #307

Hi! I encountered the same issue that Olivier mentioned. It's unclear to me how to use with_multipart_file while also including additional fields in the body. I have a case where my endpoint expects both a file and a text field in the request body, for example:

{
   "text": "text_value",
   "file": "video.mp4"
}

I tried doing it like this:

        .with_request(method="POST", path="/api/v1/check/")
        .with_body(
            body={
                "text": "text_value",
            },
            content_type="multipart/form-data",
            part="Request"
        )
        .with_multipart_file(
            part_name="file",
            path="fixtures/video.mp4",
            content_type="video/mp4",
            part="Request"
        )
        .will_respond_with(status=200)

I can't find an example of using it this way. Is it even possible to do that? In the example given above, when the test is triggered on the provider side, my service responds that the "text": "text_value" field is missing in the request.

Thanks in advance, Jakub

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIndicates new feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions