postman x-amz-content-sha 256必须是未签名的有效负载、流式处理的AWS 4-HMAC-SHA 256-有效负载或有效的sha 256值

mnemlml8  于 2022-11-07  发布在  Postman
关注(0)|答案(2)|浏览(484)

我正在尝试通过一个多格式的aws4请求发送一个图片到aws后端。我正在使用postman。下面是错误输出。

<?xml version="1.0" encoding="UTF-8"?>
  <Error>
    <Code>InvalidArgument</Code>
    <Message>x-amz-content-sha256 must be UNSIGNED-PAYLOAD, STREAMING-AWS4-HMAC-SHA256-PAYLOAD, or a valid sha256 value.</Message>
    <ArgumentName>x-amz-content-sha256</ArgumentName>
    <ArgumentValue>null</ArgumentValue>
    <RequestId>7D78494C962E781C</RequestId>
    <HostId>RLuxhuFW89Qfyspp8BCX4IaoQRqAx8yCk7OTeprRwlqH5OurASuqPNU7WbFcZPItXPcHk/8XBgw=</HostId>
  </Error>

下面是我得到的SubmitTo数据

"submitTo": {
        "url": "https://optelos-quadro.s3.amazonaws.com",
        "method": "POST",
        "contentType": "multipart/form-data",
        "formData": {
            "key": "Redacted",
            "content-type": "image/jpeg",
            "content-disposition": "inline; filename=file1.JPG",
            "x-amz-credential": "Redacted/20181015/us-west-2/s3/aws4_request",
            "x-amz-algorithm": "AWS4-HMAC-SHA256",
            "x-amz-date": "20181015T000000Z",
            "policy": "eyJleHBpcmF0aW9uIjoiMjAxOC0xMC0xNlQxNDozOTowMC4wMTBaIiwiY29uZGl0aW9ucyI6W3siYnVja2V0Ijoib3B0ZWxvcy1xdWFkcm8ifSx7ImtleSI6IjViYWQxZmU0YTE0ZmUwMDEwMDhlM2EzNy93b3JrUGFja2FnZS81YmFlNTA5M2ExNGZlMDAxMDA4ZTQyNGMvZG9jdW1lbnQvNWJjNGE2ODM4ZWUwMGYwMTAwMDdlYmZlLzViYzRhNjgzOGVlMDBmMDEwMDA3ZWJmZS5KUEcifSx7IkNvbnRlbnQtVHlwZSI6ImltYWdlL2pwZWcifSx7IkNvbnRlbnQtRGlzcG9zaXRpb24iOiJpbmxpbmU7IGZpbGVuYW1lPWZpbGUxLkpQRyJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFKUElZUVRFTTIzNTM2Q1BRLzIwMTgxMDE1L3VzLXdlc3QtMi9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE4MTAxNVQwMDAwMDBaIn1dfQ==",
            "x-amz-signature": "Redacted"
        }
    },

edqdpe6u

edqdpe6u1#

在postman中使用put而不是post,并将文件名添加到url的末尾,如/foo. txt,并在s3.之后和. www.example.com之前添加区域amazonaws.com,同时在Authorization中删除该区域
示例:https://test.s3.us-east-1.amazonaws.com/test.csv
检查下面的链接了解详细信息https://christinavhastenrath.medium.com/testing-file-uploads-to-aws-s3-with-iam-user-credentials-in-postman-5026fbde3ca6

mbzjlibv

mbzjlibv2#

这是 Postman 应用程序本身的问题,我刚刚发送http请求到AWS与节点和x-amz-content-sha 256头似乎工作。
由于这个答案太简单和简短,我将在这里添加工作JS代码:

import fs from 'fs/promises'
import FormData from 'form-data'
import fetch from 'node-fetch'

async function postToAWS() {
  const blob = fs.readFile('test.jpeg')
  const filename = 'test.jpeg'
  const bodyForm = new FormData()
  bodyForm.append('file', blob, filename)

  const response = await fetch('https://reddit-uploaded-media.s3-accelerate.amazonaws.com', {
    method: 'POST',
    body: bodyForm,
    headers: {
      'x-amz-content-sha256': ''
    }
  })
}

相关问题