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

[Bug]: APIRequestContext multipart parameter does not allow user to send multiple files in a single field #2784

Open
adriangardiner-taina opened this issue Mar 11, 2025 · 3 comments

Comments

@adriangardiner-taina
Copy link

adriangardiner-taina commented Mar 11, 2025

Version

1.50.0

Steps to reproduce

Setup a multipart data object with an array of files being sent in a single field using the ApiRequestContext object

multipart_data = {
    files= [ 
        { "name"="Document1.txt", "mimeType":"text/plain", buffer: b"Text file 1 content" },
        { "name"="Document2.txt", "mimeType":"text/plain", buffer: b"Text file 2 content" }
    ]
}

Attempt to send this to an API endpoint that expects to find a list of files against the field named "files".

Example steps : TBC

Expected behavior

I expect to receive a list of files in my API endpoint in a single form field.

Actual behavior

0 files are sent to the API Endpoint.

Additional context

Issue has been identified in playwright/_impl/_fetch.py#L382

Suggest an extra helper method and foreach loop added to identify and attach arrays of file payloads

Environment

- Operating System: [Windows 10]
- CPU: [Intel i7]
- Browser: [All]
- Python Version: [3.11.6]
- Other info:
@adriangardiner-taina
Copy link
Author

adriangardiner-taina commented Mar 11, 2025

I have a suggested fix for this which I have already used locally -

Pull Request: (#2778)

@adriangardiner-taina adriangardiner-taina changed the title WIP [Bug]: APIRequestContext multipart parameter does not allow user to send multiple files in a single field [Bug]: APIRequestContext multipart parameter does not allow user to send multiple files in a single field Mar 12, 2025
@mxschmitt
Copy link
Member

Looks like also something which would affect upstream, I'll move it for now until we have decided how we want to move forward on this. Once we decided how to fix it all the language bindings would consume the same fix.

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python Mar 12, 2025
@dgozman
Copy link
Contributor

dgozman commented Mar 17, 2025

This is a duplicate of microsoft/playwright#28070 that has been fixed in Node.js by microsoft/playwright#30489 by accepting FormData objects. In requests, you can pass a list of tuples in this case.

@dgozman dgozman transferred this issue from microsoft/playwright Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants