Created
November 22, 2017 02:18
-
-
Save jsoendermann/fcec332031ff0baea824af972c983c93 to your computer and use it in GitHub Desktop.
阿里云 Aliyun OSS curl upload 上传
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESOURCE="/${OSS_BUCKET_NAME}/${OBJECT_NAME}" | |
CONTENT_MD5=$(openssl dgst -md5 -binary "${FILEPATH}" | openssl enc -base64) | |
CONTENT_TYPE=$(file -ib "${FILEPATH}" |awk -F ";" '{print $1}') | |
DATE_VALUE="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`" | |
STRING_TO_SIGN="PUT\n${CONTENT_MD5}\n${CONTENT_TYPE}\n${DATE_VALUE}\n${RESOURCE}" | |
SIGNATURE=$(echo -e -n $STRING_TO_SIGN | openssl dgst -sha1 -binary -hmac $OSS_ACCESS_KEY_SECRET | openssl enc -base64) | |
URL="http://${OSS_BUCKET_NAME}.${OSS_REGION}.aliyuncs.com/${OBJECT_NAME}" | |
curl -i -q -X PUT -T "${FILEPATH}" \ | |
-H "Host: ${OSS_BUCKET_NAME}.${OSS_REGION}.aliyuncs.com" \ | |
-H "Date: ${DATE_VALUE}" \ | |
-H "Content-Type: ${CONTENT_TYPE}" \ | |
-H "Content-MD5: ${CONTENT_MD5}" \ | |
-H "Authorization: OSS ${OSS_ACCESS_KEY_ID}:${SIGNATURE}" \ | |
${URL} |
如何使用?
In case that your OS language is not English, use LC_ALL=C
to ensure %a
displaying English abbreviation.
$ TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'
五, 13 11 2020 04:16:21 GMT
$ LC_ALL=C TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'
Fri, 13 Nov 2020 04:16:26 GMT
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use ?