@@ -34,7 +34,7 @@ class MultipartStreamBuilder
3434 private $ boundary ;
3535
3636 /**
37- * @var array Element where each Element is an array with keys ['contents', 'headers', 'filename' ]
37+ * @var array Element where each Element is an array with keys ['contents', 'headers']
3838 */
3939 private $ data = [];
4040
@@ -72,6 +72,24 @@ public function __construct($streamFactory = null)
7272 }
7373 }
7474
75+ /**
76+ * Add a resource to the Multipart Stream
77+ *
78+ * @param string|resource|\Psr\Http\Message\StreamInterface $resource
79+ * The filepath, resource or StreamInterface of the data.
80+ * @param array $headers
81+ * Additional headers array: ['header-name' => 'header-value'].
82+ *
83+ * @return MultipartStreamBuilder
84+ */
85+ public function addData ($ resource , array $ headers = [])
86+ {
87+ $ stream = $ this ->createStream ($ resource );
88+ $ this ->data [] = ['contents ' => $ stream , 'headers ' => $ headers ];
89+
90+ return $ this ;
91+ }
92+
7593 /**
7694 * Add a resource to the Multipart Stream.
7795 *
@@ -104,9 +122,8 @@ public function addResource($name, $resource, array $options = [])
104122 }
105123
106124 $ this ->prepareHeaders ($ name , $ stream , $ options ['filename ' ], $ options ['headers ' ]);
107- $ this ->data [] = ['contents ' => $ stream , 'headers ' => $ options ['headers ' ], 'filename ' => $ options ['filename ' ]];
108125
109- return $ this ;
126+ return $ this -> addData ( $ stream , $ options [ ' headers ' ]) ;
110127 }
111128
112129 /**
0 commit comments