簡體   English   中英

使用CURL使用元數據創建S3對象失敗

[英]S3 Object Creation with meta-data using CURL is failing

我正在嘗試執行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:qatester\n"
sig="$(printf "PUT\n$md5\n$content_type\n$date\n$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>

我在這里想念什么嗎?

謝謝

您似乎在存儲桶名稱之前缺少/

date\n$daheader$bucket/$path  # incorrect
date\n$daheader/$bucket/$path # correct

在您要卷曲的實際URL中,存儲桶名稱之后也缺少/

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

有了這兩個更改,腳本就可以為我工作。

另外請注意,這不是 Signature V4。 這是簽名V2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM