-
-
Save hzbd/8238c01cef8f1d07d0d2c6cde4b817a2 to your computer and use it in GitHub Desktop.
阿里云 Aliyun OSS curl upload 上传
This file contains hidden or 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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment