0

我正在尝试使用sttp(zio version)来调用 aws s3 存储桶上传。以下是我正在使用的代码:

AsyncHttpClientZioBackend().flatMap { backend =>
      client3.basicRequest.multipartBody(
          multipart("key", data.key, UTF8_CONST),
          multipart("Content-Type", data.`Content-Type`,UTF8_CONST),
          multipart("x-amz-meta-qqfilename", data.`x-amz-meta-qqfilename`, UTF8_CONST),
          multipart("x-amz-algorithm", data.`x-amz-algorithm`, UTF8_CONST),
          multipart("x-amz-credential", data.`x-amz-credential`, UTF8_CONST),
          multipart("x-amz-date", data.`x-amz-date`, UTF8_CONST),
          multipart("x-amz-meta-entity", data.`x-amz-meta-entity`, UTF8_CONST),
          multipart("Content-Disposition", data.`Content-Disposition`, UTF8_CONST),
          multipart("acl", data.acl, UTF8_CONST),
          multipart("bucket", data.bucket, UTF8_CONST),
          multipart("policy", data.policy, UTF8_CONST),
          multipart("x-amz-signature", data.`x-amz-signature`, UTF8_CONST),
          multipartFile("file", fileObj).fileName("abc.html").contentType("text/html")
      ).post(uri"${url}")
        .send(backend)
    }.map(_.body match {
        case Left(value) =>
          println(value)
          throw new Exception("aws failed")
        case Right(value) =>
        println(s"key is ${data.key}")
      })

它取得了成功,postman但在这里失败了,说有不止一个属性。我得到的确切错误如下:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidPolicyDocument</Code>
<Message>Invalid Policy:
 Invalid Simple-Condition:
 Simple-Conditions must have exactly one property specified.
</Message>
<RequestId>PSBAM7V9A3BT5PAE</RequestId>
<HostId>fpt6ZMrjv39Q6FVpJSIQsGNhL6lz2KUhVtsyYhoWhuZ/G/u3Jux7HDxdfLyRAMhH0VUXXH3QJM4=</HostId></Error>

也许 sttp 正在以不同的方式考虑身体的各个部位,因为最终它也获得了成功akka-http

val formData = {
      Multipart.FormData(
        Multipart.FormData.BodyPart(
          "key", firstResponse.fields.key),
        Multipart.FormData.BodyPart(
          "Content-Type", firstResponse.fields.`Content-Type`),
        Multipart.FormData.BodyPart(
          "x-amz-meta-qqfilename", firstResponse.fields.`x-amz-meta-qqfilename`),
        Multipart.FormData.BodyPart(
          "x-amz-algorithm", firstResponse.fields.`x-amz-algorithm`),
        Multipart.FormData.BodyPart(
          "x-amz-credential", firstResponse.fields.`x-amz-credential`),
        Multipart.FormData.BodyPart(
          "x-amz-date", firstResponse.fields.`x-amz-date`),
        Multipart.FormData.BodyPart(
          "x-amz-meta-entity", firstResponse.fields.`x-amz-meta-entity`),
        Multipart.FormData.BodyPart(
          "Content-Disposition", firstResponse.fields.`Content-Disposition`),
        Multipart.FormData.BodyPart(
          "acl", firstResponse.fields.acl),
        Multipart.FormData.BodyPart(
          "bucket", firstResponse.fields.bucket),
        Multipart.FormData.BodyPart(
          "policy", firstResponse.fields.policy),
        Multipart.FormData.BodyPart(
          "x-amz-signature", firstResponse.fields.`x-amz-signature`),
        Multipart.FormData.BodyPart(
          "file",
          HttpEntity(ContentTypes.`text/html(UTF-8)`, "str\ndsfdf\nsdfsdf\n"))
      )
    }
    println(s"Form data: $formData")
    Marshal(formData).to[RequestEntity]
4

0 回答 0