Reputation: 21
I am trying to send an image to an aws backend via a multi-form aws4 request. I am using postman. Below is the error output.
<?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>
Below is the SubmitTo
data I got
"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"
}
},
Upvotes: 2
Views: 19733
Reputation: 21
Use put instead of post in postman and add the name of the file to the end of the url like /foo.txt and the region after the s3. and before the .amazonaws.com also remove the region in the Authorization
example: https://test.s3.us-east-1.amazonaws.com/test.csv
check the below link for details https://christinavhastenrath.medium.com/testing-file-uploads-to-aws-s3-with-iam-user-credentials-in-postman-5026fbde3ca6
Upvotes: 2
Reputation: 738
This is issue with the Postman app itself, I just sent http request to AWS with Node and x-amz-content-sha256 header seem to work.
And since this answer is too simple and short, I'll add working JS code here:
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': ''
}
})
}
Upvotes: 0