@@ -83,16 +83,16 @@ public function readObject($urn) {
8383 *
8484 * @param string $urn the unified resource name used to identify the object
8585 * @param StreamInterface $stream stream with the data to write
86- * @param string|null $mimetype the mimetype to set for the remove object @since 22.0.0
86+ * @param array $metaData the metadata to set for the object
8787 * @throws \Exception when something goes wrong, message will be logged
8888 */
89- protected function writeSingle (string $ urn , StreamInterface $ stream , ? string $ mimetype = null ): void {
89+ protected function writeSingle (string $ urn , StreamInterface $ stream , array $ metaData ): void {
9090 $ this ->getConnection ()->putObject ([
9191 'Bucket ' => $ this ->bucket ,
9292 'Key ' => $ urn ,
9393 'Body ' => $ stream ,
9494 'ACL ' => 'private ' ,
95- 'ContentType ' => $ mimetype ,
95+ 'ContentType ' => $ metaData [ ' mimetype ' ] ?? null ,
9696 'StorageClass ' => $ this ->storageClass ,
9797 ] + $ this ->getSSECParameters ());
9898 }
@@ -103,10 +103,10 @@ protected function writeSingle(string $urn, StreamInterface $stream, ?string $mi
103103 *
104104 * @param string $urn the unified resource name used to identify the object
105105 * @param StreamInterface $stream stream with the data to write
106- * @param string|null $mimetype the mimetype to set for the remove object
106+ * @param array $metaData the metadata to set for the object
107107 * @throws \Exception when something goes wrong, message will be logged
108108 */
109- protected function writeMultiPart (string $ urn , StreamInterface $ stream , ? string $ mimetype = null ): void {
109+ protected function writeMultiPart (string $ urn , StreamInterface $ stream , array $ metaData ): void {
110110 $ attempts = 0 ;
111111 $ uploaded = false ;
112112 $ concurrency = $ this ->concurrency ;
@@ -122,7 +122,7 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, ?string
122122 'part_size ' => $ this ->uploadPartSize ,
123123 'state ' => $ state ,
124124 'params ' => [
125- 'ContentType ' => $ mimetype ,
125+ 'ContentType ' => $ metaData [ ' mimetype ' ] ?? null ,
126126 'StorageClass ' => $ this ->storageClass ,
127127 ] + $ this ->getSSECParameters (),
128128 ]);
@@ -156,15 +156,15 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, ?string
156156 }
157157 }
158158
159-
160- /**
161- * @param string $urn the unified resource name used to identify the object
162- * @param resource $stream stream with the data to write
163- * @param string|null $mimetype the mimetype to set for the remove object @since 22.0.0
164- * @throws \Exception when something goes wrong, message will be logged
165- * @since 7.0.0
166- */
167159 public function writeObject ($ urn , $ stream , ?string $ mimetype = null ) {
160+ $ metaData = [];
161+ if ($ mimetype ) {
162+ $ metaData ['mimetype ' ] = $ mimetype ;
163+ }
164+ $ this ->writeObjectWithMetaData ($ urn , $ stream , $ metaData );
165+ }
166+
167+ public function writeObjectWithMetaData (string $ urn , $ stream , array $ metaData ): void {
168168 $ canSeek = fseek ($ stream , 0 , SEEK_CUR ) === 0 ;
169169 $ psrStream = Utils::streamFor ($ stream );
170170
@@ -179,16 +179,16 @@ public function writeObject($urn, $stream, ?string $mimetype = null) {
179179 $ buffer ->seek (0 );
180180 if ($ buffer ->getSize () < $ this ->putSizeLimit ) {
181181 // buffer is fully seekable, so use it directly for the small upload
182- $ this ->writeSingle ($ urn , $ buffer , $ mimetype );
182+ $ this ->writeSingle ($ urn , $ buffer , $ metaData );
183183 } else {
184184 $ loadStream = new Psr7 \AppendStream ([$ buffer , $ psrStream ]);
185- $ this ->writeMultiPart ($ urn , $ loadStream , $ mimetype );
185+ $ this ->writeMultiPart ($ urn , $ loadStream , $ metaData );
186186 }
187187 } else {
188188 if ($ size < $ this ->putSizeLimit ) {
189- $ this ->writeSingle ($ urn , $ psrStream , $ mimetype );
189+ $ this ->writeSingle ($ urn , $ psrStream , $ metaData );
190190 } else {
191- $ this ->writeMultiPart ($ urn , $ psrStream , $ mimetype );
191+ $ this ->writeMultiPart ($ urn , $ psrStream , $ metaData );
192192 }
193193 }
194194 $ psrStream ->close ();
0 commit comments