我正在尝试为我的 .bashrc 创建一个脚本,该脚本适用于匿名文件上传服务 file.io...
这是我一直在使用的,但这个是用于 transfer.sh 的服务:
# anonymous file uploading to transfer.sh via command line ($ upload file.any)
upload() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi
tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }
效果很好!但是下面来自 file.io 网站的代码对我一点帮助都没有。我觉得我已经尝试了一切,但到目前为止我并不是最擅长编码的......
curl -F "file=test.txt" https://file.io
{"success":true,"key":"2ojE41","link":"https://file.io/2ojE41","expiry":"14 days"}
我尝试了很多不同的东西,第一个是:(还有许多不同的变体)
upload2 () {
curl -F "file=$1" https://file.io
{"success":true,"key":"2ojE41","link":"https://file.io/2ojE41","expiry":"14 days"}
}
谁能帮我学习一下?
以下对我有用。
upload2(){
curl -F "file=@$1" https://file.io
}
然后就可以使用upload2 Testfile
并得到回应:{"success":true,"key":"d8Lobo","link":"https://file.io/d8Lobo","expiry":"14 days"}
我是一名优秀的程序员,十分优秀!