[关闭]
@zphj1987 2016-11-11T13:59:20.000000Z 字数 880 阅读 1301

test

test


使用bash 实现对S3文件上传,包含metadata,acl、content-type设置,以及文件md5校验。

  1. #!/bin/bash
  2. ACCESS_KEY=""
  3. SECRET_KEY=""
  4. HOST="s3.demo.com"
  5. BUCKET="demo"
  6. CONTENT_TYPE="application/octet-stream"
  7. FILENAME=/tmp/demo
  8. ACL="x-amz-acl:public-read"
  9. META_DATA="x-amz-meta-ukey:value"
  10. FILESIZE=$(stat -c%s "$FILENAME")
  11. FILEMD5=`cat ${FILENAME}| openssl dgst -md5 -binary | openssl enc -base64`
  12. AUTH_PATH="/${BUCKET}${FILENAME}"
  13. CURRENT_TIME=`TZ=GMT LANG=en_US date "+%a, %d %b %Y %H:%M:%S GMT"`
  14. stringToSign="PUT\n${FILEMD5}\n${CONTENT_TYPE}\n${CURRENT_TIME}\n${ACL}\n${META_DATA}\n${AUTH_PATH}"
  15. signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${SECRET_KEY} -binary | base64`
  16. curl -s -v -X PUT "http://${HOST}${AUTH_PATH}" \
  17. -H "Authorization: AWS ${ACCESS_KEY}:${signature}" \
  18. -H "Date: ${CURRENT_TIME}" \
  19. -H "Host: ${HOST}" \
  20. -H "Content-Length: ${FILESIZE}" \
  21. -H "Content-MD5: ${FILEMD5} " \
  22. -H "Content-Type: ${CONTENT_TYPE} " \
  23. -H "${ACL} " \
  24. -H "${META_DATA} " \
  25. -T "${FILENAME}"
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注