diff --git a/src/main/scala/zio/s3/Live.scala b/src/main/scala/zio/s3/Live.scala index e97726c3..dd065fca 100644 --- a/src/main/scala/zio/s3/Live.scala +++ b/src/main/scala/zio/s3/Live.scala @@ -120,9 +120,11 @@ final class Live(unsafeClient: S3AsyncClient) extends S3.Service { ): ZIO[R, S3Exception, Unit] = content .mapChunks(Chunk.single) - .map(c => ByteBuffer.wrap(c.toArray)) - .toPublisher - .flatMap(publisher => + .mapError(e => S3Exception.builder().message(e.getMessage).cause(e).build()) + .refineOrDie { + case e: S3Exception => e + } + .mapM { chunk => execute( _.putObject( { @@ -137,10 +139,11 @@ final class Live(unsafeClient: S3AsyncClient) extends S3.Service { .fold(builder)(builder.contentType) .build() }, - AsyncRequestBody.fromPublisher(publisher) + AsyncRequestBody.fromBytes(chunk.toArray) ) ) - ) + } + .runCollect .unit def multipartUpload[R](