cURL:上传时如何显示进度信息?

我使用以下语法上传文件:

curl --form upload=@localfilename --form press=OK [URL]

如何显示进度?谢谢。

这是我在我的一个构建脚本中使用的:

curl "${UPLOAD_URL}" \
    --progress-bar \
    --verbose \
    -F build="${BUILD}" \
    -F version="${VERSION}" \
    -F ipa="@${IPA};type=application/octet-stream" \
    -F assets="@-;type=text/xml" \
    -F replace="${REPLACE}" \
    -A "${CURL_FAKE_USER_AGENT}" \
    <<< "${ASSETS}" \
    | tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0

-F和-A选项可能不会对您感兴趣,但有用的部分是:

curl "${UPLOAD_URL}" --progress-bar

这告诉卷曲在上传期间显示进度条(而不是默认的“进度计”),以及:

 | tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0

它将命令的输出附加到日志文件,并将其回显到stdout。测试$ {PIPESTATUS [0]} -eq 0部分使得这个行(在bash脚本中)的退出状态与curl命令返回的退出代码相同,而不是tee命令的退出状态(因为三通实际上是在这条线上执行的最后一个命令,而不是卷曲)。

从人卷曲:

PROGRESS METER
       curl normally displays a progress meter during operations, indicating the amount of transferred data, transfer speeds and estimated time left, etc.

       curl  displays  this  data to the terminal by default, so if you invoke curl to do an operation and it is about to write data to the terminal, it disables the progress meter as otherwise it would mess up the
       output mixing progress meter and response data.

       If you want a progress meter for HTTP POST or PUT requests, you need to redirect the response output to a file, using shell redirect (>), -o [file] or similar.

       It is not the same case for FTP upload as that operation does not spit out any response data to the terminal.

       If you prefer a progress "bar" instead of the regular meter, -# is your friend.

OPTIONS
       -#, --progress-bar
              Make curl display progress as a simple progress bar instead of the standard, more informational, meter.
翻译自:https://stackoverflow.com/questions/9973056/curl-how-to-display-progress-information-while-uploading

转载注明原文:cURL:上传时如何显示进度信息?