-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathrs_fetch.c
58 lines (47 loc) · 1.89 KB
/
rs_fetch.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
//
// 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_FetchRet fetchRet;
Qiniu_Client client;
char *accessKey = getenv("QINIU_ACCESS_KEY");
char *secretKey = getenv("QINIU_SECRET_KEY");
char *bucket = getenv("QINIU_TEST_BUCKET");
char *resURL = "http://devtools.qiniu.com/qiniu.png";
char *key = "qiniu.png";
Qiniu_Mac mac;
mac.accessKey = accessKey;
mac.secretKey = secretKey;
Qiniu_Client_InitMacAuth(&client, 1024, &mac);
//fetch with key
Qiniu_Error error1 = Qiniu_RS_Fetch(&client, &fetchRet, resURL, bucket, key);
if (error1.code != 200) {
printf("fetch file %s -> %s:%s error.\n", resURL, bucket, key);
debug_log(&client, error1);
} else {
/*200, 正确返回了, 你可以通过fetchRet变量查询一些关于这个文件的信息*/
printf("fetch file %s -> %s:%s success.\n", resURL, bucket, key);
printf("file key: \t%s\n", fetchRet.key);
printf("file hash: \t%s\n", fetchRet.hash);
printf("file size: \t%lld\n", fetchRet.fsize);
printf("file mime type: \t%s\n", fetchRet.mimeType);
}
//fetch without key
Qiniu_Error error2 = Qiniu_RS_Fetch(&client, &fetchRet, resURL, bucket, 0);
if (error2.code != 200) {
printf("fetch file %s -> %s error.\n", resURL, bucket);
debug_log(&client, error2);
} else {
/*200, 正确返回了, 你可以通过fetchRet变量查询一些关于这个文件的信息*/
printf("fetch file %s -> %s success.\n", resURL, bucket);
printf("file key: \t%s\n", fetchRet.key);
printf("file hash: \t%s\n", fetchRet.hash);
printf("file size: \t%lld\n", fetchRet.fsize);
printf("file mime type: \t%s\n", fetchRet.mimeType);
}
Qiniu_Client_Cleanup(&client);
}