我正在尝试使用邮递员上传文件。我已通过单击“正文”(在邮递员中)->二进制->选择文件来附加文件。我使用S3上传带有预签名的网址。在url中,文件名与我在邮递员中选择的文件名完全相同。运行请求时,出现错误:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>...</AWSAccessKeyId>
<StringToSign>PUT
text/plain
1551977056
x-amz-acl:private
/wiivv-staging-private-storage/measurement/6506684788010901504/1551405460831/topLeft-2.jpeg</StringToSign>
<SignatureProvided>...</SignatureProvided>
<StringToSignBytes>...</StringToSignBytes>
<RequestId>DB2FC5FE064CF49A</RequestId>
<HostId>zbsLj7mcuXJa8D9JX1jFN1Lo+lI02/EvJreAXmPQjPezmU1sucQamXuqlGoUBzAq3nAaejx3doA=</HostId>
</Error>
但是,通过导出邮递员请求(单击“代码”)以获取curl命令,我得到了:
curl -X PUT \
'[s3-presigned-url]' \
-H 'Postman-Token: 84700b0d-0cd2-4de5-b52c-7de39a12253e' \
-H 'cache-control: no-cache'
并添加用于上传文件的其他选项:
curl -X PUT \
'[s3-presigned-url]' \
-H 'Postman-Token: 84700b0d-0cd2-4de5-b52c-7de39a12253e' \
-H 'cache-control: no-cache'
--upload-file ~/topLeft-2.jpeg
成功了!
总之,在邮递员中,它不起作用,并且在添加了--upload-file
选项的情况下,相同的请求以curl的形式导出了,它确实...
如何使请求与邮递员一起使用?
编辑1:
看起来它与错误https://github.com/postmanlabs/postman-app-support/issues/2521有关,即使没有提供标题,邮递员也会自动添加Content-Type: text/plain
标题。
编辑2:
这里是邮递员控制台的屏幕截图。看到不需要的content-type
标头了吗?
但是,如果切换Pretty
输出,则看不到该标题:
编辑3: 使用“内容类型:multipart / form-data”,我得到
PUT /measurement/6506684788010901504/1551405460831/topLeft-2.jpeg?AWSAccessKeyId=AKIAIKNR3HJGZI24MDTQ&Expires=1554393626&Signature=OaqaUqB2%2B3jp2AH97aWKujV3ZD8%3D&x-amz-acl=private
Content-Type: multipart/form-data; boundary=--------------------------092560820091438222667657
cache-control: no-cache
Postman-Token: e45247b4-0fc4-4adb-8e7b-effb82dc8e73
User-Agent: PostmanRuntime/7.6.1
Accept: */*
Host: wiivv-staging-private-storage.s3.amazonaws.com
accept-encoding: gzip, deflate
content-length: 199703
name=topLeft-2.jpegfilename=[object Object]
HTTP/1.1 403
status: 403
x-amz-request-id: 640967A618ABD4A0
x-amz-id-2: IVZtpEDxEEo0R7JaQWrsOi8/6UESbKH4dZNWDnwJDJBhv1ppZx56cvMPt6xT4ZJ3qWiFernsu54=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Thu, 04 Apr 2019 15:58:34 GMT
Connection: close
Server: AmazonS3
<?xml version="1.0" encoding="UTF-8"?> <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAIKNR3HJGZI24MDTQ</AWSAccessKeyId><StringToSign>PUT multipart/form-data; boundary=--------------------------092560820091438222667657 1554393626 x-amz-acl:private /wiivv-staging-private-storage/measurement/6506684788010901504/1551405460831/topLeft-2.jpeg</StringToSign><SignatureProvided>OaqaUqB2+3jp2AH97aWKujV3ZD8=</SignatureProvided><StringToSignBytes>50 55 54 0a 0a 6d 75 6c 74 69 70 61 72 74 2f 66 6f 72 6d 2d 64 61 74 61 3b 20 62 6f 75 6e 64 61 72 79 3d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 30 39 32 35 36 30 38 32 30 30 39 31 34 33 38 32 32 32 36 36 37 36 35 37 0a 31 35 35 34 33 39 33 36 32 36 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 72 69 76 61 74 65 0a 2f 77 69 69 76 76 2d 73 74 61 67 69 6e 67 2d 70 72 69 76 61 74 65 2d 73 74 6f 72 61 67 65 2f 6d 65 61 73 75 72 65 6d 65 6e 74 2f 36 35 30 36 36 38 34 37 38 38 30 31 30 39 30 31 35 30 34 2f 31 35 35 31 34 30 35 34 36 30 38 33 31 2f 74 6f 70 4c 65 66 74 2d 32 2e 6a 70 65 67</StringToSignBytes><RequestId>640967A618ABD4A0</RequestId><HostId>IVZtpEDxEEo0R7JaQWrsOi8/6UESbKH4dZNWDnwJDJBhv1ppZx56cvMPt6xT4ZJ3qWiFernsu54=</HostId></Error>
答案 0 :(得分:1)
不管遇到什么问题,这都是我如何解决的。在我们的应用程序逻辑中,我们现在使用给定的内容类型类型为application / octet-stream的url进行了预签名(我认为这并不重要,重要的是覆盖由邮递员桌面应用),然后我们将指定的内容类型与邮递员请求一起发送。
let s3Param = {
Bucket: this.bucketName,
Key: filePath,
Expires: bucketConfig.uploadExpireInSecond,
ACL: bucketConfig.acl,
ContentType: 'application/octet-stream',
};
s3.getSignedUrl('putObject', s3Param, ...);
,在邮递员请求标头中,我们具有“同意类型:application / octet-stream”
答案 1 :(得分:0)
您在Postman中的错误点是正确的,还是在第一步中缺少文件名,这就是签名不匹配错误的原因。当我没有传递文件名上传并“假定”我的计算机上的文件名将在S3上使用时,我遇到了签名不匹配的情况。事实并非如此。
编辑
内容类型应该是multipart / form-data,而不是纯文本。您可以在上传文件时使用name =“ filename”,如下面的示例所示。
PUT HTTP/1.1
cache-control: no-cache
Postman-Token: 98317a86-3352-48f6-bff0-e25413cb56dd
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="status.png"; filename="/Desktop/status.png