【问题标题】:Get the MD5 value of an S3 file using curl使用 curl 获取 S3 文件的 MD5 值
【发布时间】:2019-03-03 14:13:46
【问题描述】:

为了从 S3 获取特定文件,我使用如下所示的脚本:

# Get the configuration file
outputfilecfg=XXXX
amzFilecfg=XXXX
bucket=XXXX
resource="/${bucket}/${amzFilecfg}"
contentType="text/plain"
dateValue=`date -R`
stringToSigncfg="GET\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=$S3_KEY
s3Secret=$S3_SECRET
signature=`echo -en ${stringToSigncfg} | openssl sha1 -hmac ${s3Secret} -binary | base64`

curl  -H "Host: ${bucket}.s3.amazonaws.com" \
      -H "Date: ${dateValue}" \
      -H "Content-Type: ${contentType}" \
      -H "Authorization: AWS ${s3Key}:${signature}" \
      https://${bucket}.s3.amazonaws.com/${amzFilecfg} -o $outputfilecfg

现在我希望能够获得 S3 文档 (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html) 指定的对象元数据。我希望能够仅通过 curl 而不是 aws-cli 来做到这一点。这可能吗?

【问题讨论】:

  • 应该可以通过REST API获取元数据。

标签: amazon-web-services curl amazon-s3 header md5


【解决方案1】:

您可以通过发出HEAD 请求而不是GET 请求来仅获取对象元数据。要在 cURL 中发出 HEAD 请求,请使用 -I 选项。

curl  -I -H "Host: ${bucket}.s3.amazonaws.com" \
      -H "Date: ${dateValue}" \
      -H "Content-Type: ${contentType}" \
      -H "Authorization: AWS ${s3Key}:${signature}" \
      https://${bucket}.s3.amazonaws.com/${amzFilecfg} -o $outputfilecfg

有关这两种方法的更多详细信息,请参阅

【讨论】:

    猜你喜欢
    • 2014-12-12
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2011-09-09
    • 1970-01-01
    相关资源
    最近更新 更多