我正在尝试为我的.bashrc创建一个脚本,该脚本适用于匿名文件上载服务文件.io。。。
这是我一直在做的工作,但这一个是为了转移。上海的服务:

  # 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"}

10-08 04:52