[bash shell]采用表单/分片上传文件至七牛云

注意1:需要将 qshell 加入环境变量

mv qshell /usr/local/bin/qshell

http://developer.qiniu.com/code/v6/tool/qshell.html

注意2:此脚本需要注册七牛云账号,获取 ak 和 sk,以及创建 bucket 用于存储
快速入门:
http://developer.qiniu.com/article/kodo/kodo-first/quickstart.html

需要配置的参数

  1. ak sk
  2. bucket
  3. domain

shell 脚本如下:

#!/usr/bin/env bash
ii=$1
qshell account  
jj=$(ls -l | grep $ii | awk '{print $5}')

if [[ $jj -lt '100000000' ]];
    then
    echo ""
    echo "文件大小:$bb"
    echo "此文件小于100M,将采用表单上传"
    echo ""
    qshell fput  $ii $1 | tee -a test1111

    xx=$(cat test1111 | grep "Put" | awk -F ')' '{print $2}')
    rm test1111
    if [[ $xx = ' success!' ]];
        then
        echo ""
        echo "访问链接:"
        echo "http:///$ii"
        echo ""
    else
        echo "Fail, please try again!"
    fi

elif [[ $jj -ge '100000000' ]];
    then
    echo ""
    echo "文件大小:$bb"
    echo "此文件大于100M,将采用分片上传"
    echo ""
    qshell rput  $ii $1 | tee -a test1111

    xx=$(cat test1111 | grep "Put" | awk -F ')' '{print $2}')
    rm test1111
    if [[ $xx = ' success!' ]];
        then
        echo ""
        echo "访问链接:"
        echo "http:///$ii"
        echo ""
    else
        echo "Fail, please try again!"
    fi
else
    echo "File error~ 卧槽日了狗"
fi

测试截图:

qsup1

qsup2

你可能感兴趣的:([bash shell]采用表单/分片上传文件至七牛云)