Skip to content

Instantly share code, notes, and snippets.

@hzbd
Forked from jsoendermann/oss-upload.sh
Created December 19, 2020 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hzbd/8238c01cef8f1d07d0d2c6cde4b817a2 to your computer and use it in GitHub Desktop.
Save hzbd/8238c01cef8f1d07d0d2c6cde4b817a2 to your computer and use it in GitHub Desktop.
阿里云 Aliyun OSS curl upload 上传
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