File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -619,6 +619,31 @@ according to the ``multipart/form-data`` content-type. The
619
619
'body' => $formData->bodyToIterable(),
620
620
]);
621
621
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
+
622
647
By default, HttpClient streams the body contents when uploading them. This might
623
648
not work with all servers, resulting in HTTP status code 411 ("Length Required")
624
649
because 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