Skip to content

HTTP Client Multipart with multidimensional array inputs #37174

Closed
@omzy

Description

@omzy
  • Laravel Version: 8.37.0
  • PHP Version: 7.3.13
  • Database Driver & Version: MySQL 5.7.32

Description:

The fix applied in #32058 does not work for multidimensional array inputs.

Steps To Reproduce:

HTML:

<form method="post" action="" enctype="multipart/form-data">
    <input type="text" name="data[Product][user_id]">
    <input type="text" name="data[Product][supplier_id]">
    <input type="file" name="file">
</form>

PHP:

public function index(Request $request)
{
    $url = 'my-url';
    $post_data = $request->post();

    // Example of how $post_data will look
    $post_data = [
        'data[Product][user_id]' => 123,
        'data[Product][supplier_id]' => 456,
    ];

    $contents = fopen($request->file('file'), 'r');

    return Http::attach('file', $contents)
        ->post($url, $post_data);
}

This produces an error: A 'contents' key is required.

A print_r() of $laravelData (line 714 src/Illuminate/Http/Client/PendingRequest.php) outputs the following:

Array
(
    [0] => Array
        (
            [Product] => Array
                (
                    [user_id] => 123
                    [supplier_id] => 456
                )
        )

    [1] => Array
        (
            [name] => file
            [contents] => Resource id #439
        )
)

As you can see, it does not format the input variables into name and contents pairs, like it has done with the file input.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions