Skip to content

Commit

Permalink
Make sure S3.putObject respects the Content-Type on the passed object (
Browse files Browse the repository at this point in the history
  • Loading branch information
joedarby authored Jan 10, 2024
1 parent 592e011 commit c7d511b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 12 additions & 5 deletions modules/s3/src/it/scala/s3/S3Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.UUID
import common.model._
import common.{CredentialsProvider, IntegrationSpec}
import model._
import org.http4s.MediaType

class S3Spec extends IntegrationSpec with AsyncIOSpec {

Expand Down Expand Up @@ -201,23 +202,29 @@ class S3Spec extends IntegrationSpec with AsyncIOSpec {
"the bucket exists" when {
"the key does not exist" should {

"upload the object content" in {
withS3 { s3 =>
"upload the object content with correct Content-Type" in {
val (putResult, getResult) = withS3 { s3 =>
val contentIo: IO[ObjectContent[IO]] = moreSize.map { size =>
ObjectContent(
readInputStream(morePdf, chunkSize = 64 * 1024),
size,
chunked = true
chunked = true,
mediaType = MediaType.application.pdf
)
}

for {
key <- randomKey
content <- contentIo
result <- s3.putObject(existingBucket, key, content)
} yield result
getResult <- IO(checkGetObject(existingBucket, key)(identity))
} yield (result, getResult)

}.unsafeRunSync()

putResult shouldBe a[Right[_,_]]
getResult.map(_.summary.mediaType) shouldBe Right(MediaType.application.pdf)

}.unsafeRunSync() shouldBe a[Right[_, _]]
}

"upload the object content with custom metadata" in {
Expand Down
3 changes: 1 addition & 2 deletions modules/s3/src/main/scala/s3/S3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ object S3 {
for {
hs <- initHeaders
contentAsSingleChunk <- extractContent
request = Request[F](method = PUT, uri = uri(bucket, key), headers = hs)
.withEntity(contentAsSingleChunk)
request = PUT(contentAsSingleChunk, uri(bucket, key), hs)
result <- withRetry(signedClient.run(request).use {
case r if r.status.isSuccess => r.as[ObjectPut].map(_.asRight[Error])
case r if r.status.responseClass == Status.ServerError =>
Expand Down

0 comments on commit c7d511b

Please sign in to comment.