使用CURL使用元数据创建S3对象失败



我正在尝试执行HTTP PUT来创建和更新对象,同时指定自定义元数据头。我很难生成正确的签名,而为其他请求的操作生成签名没有问题。这是我的基本bash/CURL示例。让我强调一下,我必须看到并使用Bash和Curl,而不是在我的特定情况下利用s3curl或其他库或CLI:

#!/bin/bash
file="$1"
key_id="raanan"
key_secret="my-secret"
url="my-s3-endpoint"
bucket="testbucket"
path="$file"
content_type="application/octet-stream"
date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
md5="$(openssl md5 -binary < "$file" | base64)"
daheader="x-amz-meta-user:qatestern"
sig="$(printf "PUTn$md5n$content_typen$daten$daheader$bucket/$path" |    
openssl sha1 -binary -hmac "$key_secret" | base64)"
curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket$path -vv 
-H "Date: $date" 
-H "Authorization: AWS $key_id:$sig" 
-H "Content-Type: $content_type" 
-H "Content-MD5: $md5" 
-H "x-amz-meta-user: qatester"
>>>>HTTP/1.1 403 Forbidden
>>>>?xml version="1.0" encoding="UTF-8" standalone="yes"?><Error>
<Code>SignatureDoesNotMatch</Code><Message>The request signature we    calculated 
does not match the signature you provided. Check your secret access key and   signing method.</Message><Resource></Resource><RequestId></RequestId>    </Error>

我是不是遗漏了什么?

感谢

存储桶名称之前似乎缺少/

daten$daheader$bucket/$path  # incorrect
daten$daheader/$bucket/$path # correct

在您要交给curl的实际URL中的bucket名称之后,您还缺少一个/

curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket$path -vv   # incorrect
curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket/$path -vv  # correct

有了这两个变化,这个脚本对我来说是有效的

此外,请注意,这是而不是签名V4。这是签名V2。