File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -619,6 +619,35 @@ according to the ``multipart/form-data`` content-type. The
619619 'body' => $formData->bodyToIterable(),
620620 ]);
621621
622+ .. tip ::
623+
624+ When using multidimensional arrays the :class: `Symfony\\ Component\\ Mime\\ Part\\ Multipart\\ FormDataPart `
625+ automatically appends ``[key] `` to the name of the field::
626+
627+ $formData = new FormDataPart([
628+ 'array_field' => [
629+ 'some value',
630+ 'other value',
631+ ],
632+ ]);
633+
634+ $formData->getParts(); // Returns two instances of TextPart
635+ // with the names "array_field[0]" and "array_field[1]"
636+
637+ This behavior can be bypassed by using the following array structure::
638+
639+ $formData = new FormDataPart([
640+ ['array_field' => 'some value'],
641+ ['array_field' => 'other value'],
642+ ]);
643+
644+ $formData->getParts(); // Returns two instances of TextPart both
645+ // with the name "array_field"
646+
647+ .. versionadded :: 5.2
648+
649+ The alternative array structure was introduced in Symfony 5.2.
650+
622651By default, HttpClient streams the body contents when uploading them. This might
623652not work with all servers, resulting in HTTP status code 411 ("Length Required")
624653because there is no ``Content-Length `` header. The solution is to turn the body
You can’t perform that action at this time.
0 commit comments