Skip to content

Instantly share code, notes, and snippets.

@rainchen
Last active September 6, 2017 15:38
Show Gist options
  • Select an option

  • Save rainchen/a2e4b9bbaa87c703d3d0af2e82e3701c to your computer and use it in GitHub Desktop.

Select an option

Save rainchen/a2e4b9bbaa87c703d3d0af2e82e3701c to your computer and use it in GitHub Desktop.

Revisions

  1. rainchen revised this gist Sep 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion qiniu-upload
    Original file line number Diff line number Diff line change
    @@ -41,5 +41,5 @@ echo "uploadToken:$uploadToken"
    echo "Uploading..."
    echo
    # add "-v" for debug
    curl -v -F token="$uploadToken" -F file="$uploadfile" -F key="$uploadfile" -F fileBinaryData=@$uploadfile http://upload.qiniu.com/
    curl -v -F token="$uploadToken" -F file="@$uploadfile" -F key="$uploadfile" http://upload.qiniu.com/
    echo
  2. rainchen revised this gist Sep 6, 2017. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion qiniu-upload
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    #!/bin/bash

    # refs:
    # https://segmentfault.com/q/1010000003000974
    # http://blog.csdn.net/guoer9973/article/details/46459971
    # http://www.cnblogs.com/sink_cup/p/cloud_storage_aliyun_oss_vs_qiniu_rs.html

    # api:
    # https://developer.qiniu.com/kodo/api/1312/upload

    @@ -17,7 +23,7 @@ echo "Upload $uploadfile to $namespace"
    echo

    scope="$namespace"
    deadline=$(echo `date +%s` + 3600| bc )
    deadline=$(expr `date +%s` + 3600)

    # build policy json
    putPolicy="{\"scope\":\"$scope\",\"deadline\":$deadline}"
  3. rainchen revised this gist Sep 6, 2017. 1 changed file with 5 additions and 11 deletions.
    16 changes: 5 additions & 11 deletions qiniu-upload
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,4 @@
    #!/bin/bash

    # refs:
    # https://segmentfault.com/q/1010000003000974
    # http://blog.csdn.net/guoer9973/article/details/46459971
    # http://www.cnblogs.com/sink_cup/p/cloud_storage_aliyun_oss_vs_qiniu_rs.html

    # api:
    # https://developer.qiniu.com/kodo/api/1312/upload

    @@ -27,19 +21,19 @@ deadline=$(echo `date +%s` + 3600| bc )

    # build policy json
    putPolicy="{\"scope\":\"$scope\",\"deadline\":$deadline}"
    # echo "putPolicy:$putPolicy"
    echo "putPolicy:$putPolicy"

    data=$(echo -en $putPolicy | base64 | tr "+/" "-_")
    # echo "data:$data"
    echo "data:$data"

    auth=$(echo -en $data | openssl sha1 -hmac $secretkey -binary | base64 | tr "+/" "-_")
    # echo "auth:$auth"
    echo "auth:$auth"

    uploadToken="$accesskey:$auth:$data";
    # echo "uploadToken:$uploadToken"
    echo "uploadToken:$uploadToken"

    echo "Uploading..."
    echo
    # add "-v" for debug
    curl -F token="$uploadToken" -F file="$uploadfile" -F key="$uploadfile" -F fileBinaryData=@$uploadfile http://upload.qiniu.com/
    curl -v -F token="$uploadToken" -F file="$uploadfile" -F key="$uploadfile" -F fileBinaryData=@$uploadfile http://upload.qiniu.com/
    echo
  4. rainchen created this gist Sep 6, 2017.
    45 changes: 45 additions & 0 deletions qiniu-upload
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/bin/bash

    # refs:
    # https://segmentfault.com/q/1010000003000974
    # http://blog.csdn.net/guoer9973/article/details/46459971
    # http://www.cnblogs.com/sink_cup/p/cloud_storage_aliyun_oss_vs_qiniu_rs.html

    # api:
    # https://developer.qiniu.com/kodo/api/1312/upload

    # how-to-access-or-locate-the-access-key-and-secret-key
    accesskey=$(printenv 'QINIU_AK')
    secretkey=$(printenv 'QINIU_SK')
    namespace=$(printenv 'QINIU_NS')

    if [[ $accesskey == '' ]]; then
    echo 'QINIU_AK is blank'
    exit;
    fi

    uploadfile=$1
    echo "Upload $uploadfile to $namespace"
    echo

    scope="$namespace"
    deadline=$(echo `date +%s` + 3600| bc )

    # build policy json
    putPolicy="{\"scope\":\"$scope\",\"deadline\":$deadline}"
    # echo "putPolicy:$putPolicy"

    data=$(echo -en $putPolicy | base64 | tr "+/" "-_")
    # echo "data:$data"

    auth=$(echo -en $data | openssl sha1 -hmac $secretkey -binary | base64 | tr "+/" "-_")
    # echo "auth:$auth"

    uploadToken="$accesskey:$auth:$data";
    # echo "uploadToken:$uploadToken"

    echo "Uploading..."
    echo
    # add "-v" for debug
    curl -F token="$uploadToken" -F file="$uploadfile" -F key="$uploadfile" -F fileBinaryData=@$uploadfile http://upload.qiniu.com/
    echo