Delete file
Updated at:2025-11-03
Delete file
Delete single file
The following code can be referenced to delete an 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 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(&object, object_name);
16 /* test delete object */
17 s = bos_delete_object(options, &bucket, &object, &resp_headers);
18 bos_pool_destroy(p);
19 printf("test_delete_object ok\n");
20}
Delete multiple files
To delete multiple files, bos_delete_objects uses a concurrent API to improve the throughput of requests. The code is as follows:
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 bos_pool_create(&p, NULL);
15 options = bos_request_options_create(p);
16 init_test_request_options(options, is_cname);
17 bos_str_set(&bucket, TEST_BUCKET_NAME);
18 bos_list_init(&object_list);
19 bos_list_init(&deleted_object_list);
20 content1 = bos_create_bos_object_key(p);
21 bos_str_set(&content1->key, object_name1);
22 bos_list_add_tail(&content1->node, &object_list);
23 content2 = bos_create_bos_object_key(p);
24 bos_str_set(&content2->key, object_name2);
25 bos_list_add_tail(&content2->node, &object_list);
26 s = bos_delete_objects(options, &bucket, &object_list, is_quiet,
27 &resp_headers, &deleted_object_list);
Delete objects by a certain prefix
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 bos_pool_create(&p, NULL);
11 options = bos_request_options_create(p);
12 init_test_request_options(options, is_cname);
13 bos_str_set(&bucket, TEST_BUCKET_NAME);
14 bos_str_set(&prefix, prefix_str);
15 s = bos_delete_objects_by_prefix(options, &bucket, &prefix);
16 bos_pool_destroy(p);
17}
