删除文件
更新时间:2024-04-24
删除文件
删除单个文件
可参考如下代码删除了一个Object:
void test_delete_object(CuTest *tc)
{
bos_pool_t *p = NULL;
bos_string_t bucket;
char *object_name = "bos_test_put_object";
bos_string_t object;
int is_cname = 0;
bos_request_options_t *options = NULL;
bos_table_t *resp_headers = NULL;
bos_status_t *s = NULL;
bos_pool_create(&p, NULL);
options = bos_request_options_create(p);
init_test_request_options(options, is_cname);
bos_str_set(&bucket, TEST_BUCKET_NAME);
bos_str_set(&object, object_name);
/* test delete object */
s = bos_delete_object(options, &bucket, &object, &resp_headers);
bos_pool_destroy(p);
printf("test_delete_object ok\n");
}
删除多个文件
删除多个文件bos_delete_objects
使用并发接口,提高请求数的吞吐,代码如下:
bos_pool_t *p = NULL;
int is_cname = 0;
bos_string_t bucket;
bos_status_t *s = NULL;
bos_table_t *resp_headers = NULL;
bos_request_options_t *options = NULL;
char *object_name1 = "bos_tmp1/";
char *object_name2 = "bos_tmp2/";
bos_object_key_t *content1 = NULL;
bos_object_key_t *content2 = NULL;
bos_list_t object_list;
bos_list_t deleted_object_list;
int is_quiet = 0;
bos_pool_create(&p, NULL);
options = bos_request_options_create(p);
init_test_request_options(options, is_cname);
bos_str_set(&bucket, TEST_BUCKET_NAME);
bos_list_init(&object_list);
bos_list_init(&deleted_object_list);
content1 = bos_create_bos_object_key(p);
bos_str_set(&content1->key, object_name1);
bos_list_add_tail(&content1->node, &object_list);
content2 = bos_create_bos_object_key(p);
bos_str_set(&content2->key, object_name2);
bos_list_add_tail(&content2->node, &object_list);
s = bos_delete_objects(options, &bucket, &object_list, is_quiet,
&resp_headers, &deleted_object_list);
按照某个prefix删除objects
void test_delete_objects_by_prefix(CuTest *tc)
{
bos_pool_t *p = NULL;
bos_request_options_t *options = NULL;
int is_cname = 0;
bos_string_t bucket;
bos_status_t *s = NULL;
bos_string_t prefix;
char *prefix_str = "bos_tmp3/";
bos_pool_create(&p, NULL);
options = bos_request_options_create(p);
init_test_request_options(options, is_cname);
bos_str_set(&bucket, TEST_BUCKET_NAME);
bos_str_set(&prefix, prefix_str);
s = bos_delete_objects_by_prefix(options, &bucket, &prefix);
bos_pool_destroy(p);
}