-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathrs_batch_delete_after_days.c
71 lines (59 loc) · 2.16 KB
/
rs_batch_delete_after_days.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Created by jemy on 07/08/2017.
//
#include "../qiniu/rs.h"
#include <stdlib.h>
#include "debug.h"
int main(int argc, char **argv) {
Qiniu_Global_Init(-1);
Qiniu_RS_BatchItemRet *itemRets;
Qiniu_Client client;
int i;
char *accessKey = getenv("QINIU_ACCESS_KEY");
char *secretKey = getenv("QINIU_SECRET_KEY");
char *bucket = getenv("QINIU_TEST_BUCKET");
char *key = "qiniu.png";
Qiniu_Mac mac;
mac.accessKey = accessKey;
mac.secretKey = secretKey;
Qiniu_ItemCount entryCount = 10;
Qiniu_RS_EntryDeleteAfterDays *entries = (Qiniu_RS_EntryDeleteAfterDays *) malloc(
sizeof(Qiniu_RS_EntryDeleteAfterDays) * entryCount);
for (i = 0; i < entryCount; i++) {
Qiniu_RS_EntryDeleteAfterDays entry;
entry.bucket = bucket;
size_t indexLen = snprintf(NULL, 0, "%d", i) + 1;
char *indexStr = (char *) calloc(sizeof(char), indexLen);
snprintf(indexStr, indexLen, "%d", i);
entry.key = Qiniu_String_Concat2(key, indexStr);
Qiniu_Free(indexStr);
entry.days = 7;//设置7天有效期
entries[i] = entry;
}
itemRets = (Qiniu_RS_BatchItemRet *) malloc(sizeof(Qiniu_RS_BatchItemRet) * entryCount);
//init
Qiniu_Client_InitMacAuth(&client, 1024, &mac);
Qiniu_Error error = Qiniu_RS_BatchDeleteAfterDays(&client, itemRets, entries, entryCount);
if (error.code / 100 != 2) {
printf("batch deleteAfterDays file error.\n");
debug_log(&client, error);
} else {
/*200, 正确返回了, 你可以通过itemRets变量查询一些关于这个文件的信息*/
printf("batch deleteAfterDays file success.\n\n");
for (i = 0; i < entryCount; i++) {
int code = itemRets[i].code;
if (code == 200) {
printf("success: %d\n", code);
} else {
printf("code: %d, error: %s\n", code, itemRets[i].error);
}
}
}
for (i = 0; i < entryCount; i++) {
Qiniu_RS_EntryDeleteAfterDays entry = entries[i];
Qiniu_Free((void *) entry.key);
}
Qiniu_Free(entries);
Qiniu_Free(itemRets);
Qiniu_Client_Cleanup(&client);
}