Skip to content

[Mime][FormDataPart] Add support of multidimensional fields in constructor #33064

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

Closed
wants to merge 1 commit into from

Conversation

wtorsi
Copy link

@wtorsi wtorsi commented Aug 8, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #33063
License MIT
Doc PR

Add support of multidimensional fields in FormDataPart.

@wtorsi wtorsi changed the title Issue #33063 [Mime][FormDataPart] Add support of multidimensional fields in constructor Aug 8, 2019
@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Aug 8, 2019
@nicolas-grekas nicolas-grekas changed the base branch from 4.4 to 4.3 August 8, 2019 17:09
@jvahldick
Copy link
Contributor

Hi,

First of all, thanks @wtorsi for your time taking a look on this issue.

I have a similar issue when trying to POST arrays using the HttpClient component together with Mime. Let's say I am trying to send an array of tags for creating a media file.

$formFields = [
    'media' => [
        'tags' => [
            [
                'name' => 'first-tag'
            ],
            [
                'name' => 'first-tag'
            ]
        ],
    ],
];

Using the PR code, as result, I have the following field names:

name=media
name=media

However, when sending a form-data, what I expect on the backend is something like:

name=media[tags][0][name]
name=media[tags][1][name]

I changed a bit the closure function to have the result I was expecting, which I am not sure it is the correct way.

$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
    $fieldName =  $root ? $root . '['.$key.']' : $key;

    if (\is_array($item)) {
        array_walk($item, $prepare, $fieldName);

        return;
    }

    $values[] = $this->preparePart($fieldName, $item);
};

Any thoughts?

@fabpot
Copy link
Member

fabpot commented Aug 13, 2020

Closing as it seems to have been fixed by #34032

@fabpot fabpot closed this Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants