C++ libcurl 上传进度条
C++ libcurl upload progress bar
很简单:我们正在使用 libcurl 简易界面将大量文件上传到在线数据存储。
我需要显示此上传的进度。我知道所有文件信息,所以基本上我必须找出发送了多少 bits/bytes 并计算整个文件的百分比。
我翻阅了libcurl手册,但没有找到任何关于上传进度的信息,只有下载进度。
我是 libcurl 的新手,正在使用同事的函数。所以我可能漏掉了什么。
有没有使用libcurl监控上传进度的方法?
查看他们的 documentation:
For historical and traditional reasons, libcurl has a built-in
progress meter that can be switched on and then makes it present a
progress meter in your terminal.
Switch on the progress meter by, oddly enough, setting
CURLOPT_NOPROGRESS
to zero. This option is set to 1
by default.
For most applications however, the built-in progress meter is useless
and what instead is interesting is the ability to specify a progress
callback. The function pointer you pass to libcurl
will then be called
on irregular intervals with information about the current transfer.
Set the progress callback by using CURLOPT_PROGRESSFUNCTION
. And pass
a pointer to a function that matches this prototype:
int progress_callback(void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow);
If any of the input arguments is unknown, a 0 will be passed. The
first argument, the 'clientp' is the pointer you pass to libcurl with
CURLOPT_PROGRESSDATA
. libcurl won't touch it.
很简单:我们正在使用 libcurl 简易界面将大量文件上传到在线数据存储。 我需要显示此上传的进度。我知道所有文件信息,所以基本上我必须找出发送了多少 bits/bytes 并计算整个文件的百分比。
我翻阅了libcurl手册,但没有找到任何关于上传进度的信息,只有下载进度。
我是 libcurl 的新手,正在使用同事的函数。所以我可能漏掉了什么。
有没有使用libcurl监控上传进度的方法?
查看他们的 documentation:
For historical and traditional reasons, libcurl has a built-in progress meter that can be switched on and then makes it present a progress meter in your terminal.
Switch on the progress meter by, oddly enough, setting
CURLOPT_NOPROGRESS
to zero. This option is set to1
by default.For most applications however, the built-in progress meter is useless and what instead is interesting is the ability to specify a progress callback. The function pointer you pass to
libcurl
will then be called on irregular intervals with information about the current transfer.Set the progress callback by using
CURLOPT_PROGRESSFUNCTION
. And pass a pointer to a function that matches this prototype:
int progress_callback(void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow);
If any of the input arguments is unknown, a 0 will be passed. The first argument, the 'clientp' is the pointer you pass to libcurl with
CURLOPT_PROGRESSDATA
. libcurl won't touch it.