@@ -34,7 +34,7 @@ class MultipartStreamBuilder
34
34
private $ boundary ;
35
35
36
36
/**
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']
38
38
*/
39
39
private $ data = [];
40
40
@@ -72,6 +72,24 @@ public function __construct($streamFactory = null)
72
72
}
73
73
}
74
74
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
+
75
93
/**
76
94
* Add a resource to the Multipart Stream.
77
95
*
@@ -104,9 +122,8 @@ public function addResource($name, $resource, array $options = [])
104
122
}
105
123
106
124
$ this ->prepareHeaders ($ name , $ stream , $ options ['filename ' ], $ options ['headers ' ]);
107
- $ this ->data [] = ['contents ' => $ stream , 'headers ' => $ options ['headers ' ], 'filename ' => $ options ['filename ' ]];
108
125
109
- return $ this ;
126
+ return $ this -> addData ( $ stream , $ options [ ' headers ' ]) ;
110
127
}
111
128
112
129
/**
0 commit comments