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