OSS C/C++ SDK分享交流区
ReOSS C/CSDK分享交流区
分块上传大文件时加入进度条,上传成功的片数,和总片数在哪个变量里面?
新手,找了注释,但是没有发现有用的信息,只知道应该在下面的代码
List Part 里修改。
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num1, upload_file, &upload_part_resp_headers);
assert(200 == s->code);
//list part
list_part_resp_headers = aos_table_make(p, 5);
params = oss_create_list_upload_part_params(p);//所有分块信息存储在oss_list_upload_part_params_t的params中
aos_str_set(¶ms->part_number_marker, '');
params->max_ret = 10;
params->truncated = 0;
aos_list_init(&complete_part_list);
s = oss_list_upload_part(options, &bucket, &object, &upload_id, params, &list_part_resp_headers);//获取所有已上传的块信息
assert(200 == s->code);
assert(200 == s->code);
//通过aos_list_for_each_entry对part_list进行遍历。
aos_list_for_each_entry(oss_list_part_content_t, part_content1, ¶ms->part_list, node){
complete_content1 = oss_create_complete_part_content(p);
aos_str_set(&complete_content1->part_number, part_content1->part_number.data);
aos_str_set(&complete_content1->etag, part_content1->etag.data);
aos_list_add_tail(&complete_content1->node, &complete_part_list);
}
-------------------------
回 77楼yjseu的帖子
谢谢您的回复!
您的说的这些条件里,现在就是不知道“累计上传的变量”在哪里。
文件的multipart上传,就在下面的这个函数中,什么时候上传完了,才能往下执行。
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num1,
upload_file, &upload_part_resp_headers);
我想的是另开一个线程,定时读取其中的一个参数中的“累计上传”,来完成进度条。
我猜测着是不是 oss_upload_file_t *upload_file 里面的file_last 是不是我想要的东西呢。
-------------------------
Re回 79楼yjseu的帖子
太谢谢你了!
问题解决了,
关键是 oss_upload_part_from_file上传的是Part,我误以为是文件。原来官方给的示例,是不管文件多大就文件分成两个part进行发送。
现在修改了下原来的代码,更容易理解了些,下一步准备做的就是,每上传一个part就发送消息去更新进度条。 不知道理解的正确不正确,欢迎指正撒。
aos_file_buf_t * fb = aos_create_file_buf(p);
int res = aos_open_file_for_read(p, G2U('G:\\IEDownLoad\\UCode(IOCP例程).rar'), fb);
int64_t filesize = fb->file_last;
if(filesize {
AfxMessageBox('文件不能小于100KB');
return ;
}
int64_t partsize = 100 * 1024;
int64_t partupload = 0;
part_num = 1;
while(1)
{
upload_file->file_pos = partsize*(part_num-1);
upload_file->file_last = partsize*part_num; //100k
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num, upload_file, &upload_part_resp_headers);
assert(200 == s->code);
part_num++;
partupload += partsize;
if((filesize-partupload {
upload_file->file_pos = partsize*part_num;//remain content start pos
upload_file->file_last = get_file_size(G2U('G:\\IEDownLoad\\UCode(IOCP例程).rar'))-partupload;
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num, upload_file, &upload_part_resp_headers);
assert(200 == s->code);
break;
}
}
-------------------------
回 81楼yjseu的帖子
嗯嗯,现在解决了。衷心感谢你们的努力!
-------------------------
ReOSS C/CSDK分享交流区
现在有个问题就是,分块的话 不管多大的part 只能 上传成功10个,比如用100KB上传3M 文件,网站上只有1M。(程序调试没有出现错误,不知道网站有没有给错误响应)
aos_table_make(p,0); 请问这个语句是什么功能?
我的test_multipart_upload_from_file(LPVOID para) 代码也贴出来吧。
UINT test_multipart_upload_from_file(LPVOID para)
{
if (aos_http_io_initialize('oss_test', 0) != AOSE_OK) {
exit(1);
}
Coos_demoDlg * oos_demoDlg = (Coos_demoDlg *)para;
char *object_name = G2U(oos_demoDlg->m_sFilename);
aos_pool_t *p;
aos_string_t bucket;
aos_string_t object;
int is_oss_domain = 1;
oss_request_options_t *options;
aos_status_t *s;
oss_upload_file_t *upload_file;
aos_table_t *upload_part_resp_headers;
oss_list_upload_part_params_t *params;
aos_table_t *list_part_resp_headers;
aos_string_t upload_id;
aos_list_t complete_part_list;
oss_list_part_content_t *part_content1;
oss_complete_part_content_t *complete_content1;
aos_table_t *complete_resp_headers;
int part_num = 1;
int part_num1 = 2;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_test_request_options(options, is_oss_domain);
aos_str_set(&bucket, TEST_BUCKET_NAME);
aos_str_set(&object, object_name);
//init mulitipart
s = init_test_multipart_upload(options, TEST_BUCKET_NAME, object_name, &upload_id);
assert(200 == s->code);
//upload part from file
upload_part_resp_headers = aos_table_make(p,0);
upload_file = oss_create_upload_file(p);
aos_str_set(&upload_file->filename, G2U(oos_demoDlg->m_sPath));
aos_file_buf_t * fb = aos_create_file_buf(p);
int res = aos_open_file_for_read(p, G2U(oos_demoDlg->m_sPath), fb);
int64_t filesize = fb->file_last;
int64_t partsize;
filesize/10>100*1024? partsize = filesize/10:partsize = 100*1024;
int64_t partupload = 0;
part_num = 1;
/********** 进度条***************/
//创建用户界面线程,用于进度的显示
oos_demoDlg->m_pUIThread=AfxBeginThread(RUNTIME_CLASS(CcbCopyFile));
if (oos_demoDlg->m_pUIThread == NULL)
{
AfxMessageBox('用户界面线程启动失败!',MB_OK|MB_ICONERROR);
return 0;
}//传递参数
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO,0,(LPARAM)(oos_demoDlg->m_sPath.GetBuffer(0)));
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO,1,(LPARAM)'服务器');
SetTimer(oos_demoDlg->m_hWnd,1,1000,NULL);//速度统计
SetTimer(oos_demoDlg->m_hWnd,2,100,NULL);//操作计时
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO,2,1);//启动
//////////////////////
while(1)
{
if((filesize-partupload {
upload_file->file_pos = partupload;//remain content start pos
upload_file->file_last = filesize;
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num, upload_file, &upload_part_resp_headers);
//**********更新进度****************/
oos_demoDlg->m_nSpeed1 = partupload;
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO, 3,
(LPARAM) int((partupload*1.0/filesize)*100));
/////////////////////////////
assert(200 == s->code);
break;
}
upload_file->file_pos = partsize*(part_num-1);
upload_file->file_last = partsize*part_num; //100k
s = oss_upload_part_from_file(options, &bucket, &object, &upload_id,
part_num, upload_file, &upload_part_resp_headers);
part_num++;
partupload += partsize;
//**********更新进度****************/
oos_demoDlg->m_nSpeed1 = partupload;
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO, 3,
(LPARAM) int((partupload*1.0/filesize)*100));
/////////////////////////////
assert(200 == s->code);
}
//发送结束消息,用于关闭进度显示模块
oos_demoDlg->m_pUIThread->PostThreadMessage(WM_THREADINFO, 10, 1);
oos_demoDlg->KillTimer(1);
oos_demoDlg->KillTimer(2);
//////////////////
//list part
list_part_resp_headers = aos_table_make(p, 0);
params = oss_create_list_upload_part_params(p);//所有分块信息存储在oss_list_upload_part_params_t的params中
aos_str_set(¶ms->part_number_marker, '');
params->max_ret = 10;
params->truncated = 0;
aos_list_init(&complete_part_list);
s = oss_list_upload_part(options, &bucket, &object, &upload_id, params, &list_part_resp_headers);//获取所有已上传的块信息
assert(200 == s->code);
//通过aos_list_for_each_entry对part_list进行遍历。
aos_list_for_each_entry(oss_list_part_content_t, part_content1, ¶ms->part_list, node){
complete_content1 = oss_create_complete_part_content(p);
aos_str_set(&complete_content1->part_number, part_content1->part_number.data);
aos_str_set(&complete_content1->etag, part_content1->etag.data);
aos_list_add_tail(&complete_content1->node, &complete_part_list);
}
//complete multipart
complete_resp_headers = aos_table_make(p, 0);
s = oss_complete_multipart_upload(options, &bucket, &object, &upload_id,
&complete_part_list, &complete_resp_headers); //接口,完成分块上传
assert(200 == s->code);
aos_pool_destroy(p);
AfxMessageBox('上传成功');
//delete object_name;
aos_http_io_deinitialize();
return 0;
}
-------------------------
ReOSS C/CSDK分享交流区
可算搞定了,params->max_ret = 10; 应该就是最大Part数,真是一步一艰难啊 虽然还是有好多语句不懂,
赞0
踩0