void testIoPut() { Qiniu_Error err; Qiniu_Client client; Qiniu_RS_PutPolicy putPolicy; Qiniu_RS_GetPolicy getPolicy; char* uptoken; char* dntoken; Qiniu_Client_InitMacAuth(&client, 1024, NULL); Qiniu_Zero(putPolicy); putPolicy.scope = bucket; uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, NULL); Qiniu_RS_Delete(&client, bucket, key); clientIoPutFile(uptoken); Qiniu_RS_Delete(&client, bucket, key); clientIoPutBuffer(uptoken); free(uptoken); Qiniu_Zero(getPolicy); getPolicy.scope = "*/*"; dntoken = Qiniu_RS_GetPolicy_Token(&getPolicy, NULL); clientIoGet(dntoken); free(dntoken); Qiniu_Client_Cleanup(&client); }
void testResumableIoPut(void) { Qiniu_Client client; Qiniu_RS_PutPolicy putPolicy; Qiniu_RS_GetPolicy getPolicy; char* uptoken; char* dnBaseUrl; char* dnRequest; Qiniu_Client_InitMacAuth(&client, 1024, NULL); Qiniu_Zero(putPolicy); putPolicy.scope = bucket; uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, NULL); Qiniu_RS_Delete(&client, bucket, key); clientIoPutFile(uptoken); Qiniu_RS_Delete(&client, bucket, key); clientIoPutBuffer(uptoken); Qiniu_Free(uptoken); Qiniu_Zero(getPolicy); dnBaseUrl = Qiniu_RS_MakeBaseUrl(domain, key); dnRequest = Qiniu_RS_GetPolicy_MakeRequest(&getPolicy, dnBaseUrl, NULL); clientIoGet(dnRequest); Qiniu_Free(dnRequest); Qiniu_Free(dnBaseUrl); Qiniu_Client_Cleanup(&client); }
void up_chunk_upload() { Qiniu_Global_Init(-1); Qiniu_Rio_PutRet putRet; Qiniu_Client client; Qiniu_RS_PutPolicy putPolicy; Qiniu_Rio_PutExtra putExtra; char *accessKey = getenv("QINIU_ACCESS_KEY"); char *secretKey = getenv("QINIU_SECRET_KEY"); char *bucket = getenv("QINIU_TEST_BUCKET"); char *key = "2017/08/12/upload.mp4"; char *localFile = "E:\\Data\\upload.mp4"; Qiniu_Mac mac; mac.accessKey = accessKey; mac.secretKey = secretKey; Qiniu_Zero(putPolicy); Qiniu_Zero(putExtra); putPolicy.scope = bucket; char *uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, &mac); //设置机房域名 //Qiniu_Use_Zone_Beimei(Qiniu_False); //Qiniu_Use_Zone_Huabei(Qiniu_True); Qiniu_Use_Zone_Huadong(Qiniu_False); //Qiniu_Use_Zone_Huanan(Qiniu_True); //put extra //putExtra.upHost="http://nbxs-gate-up.qiniu.com"; putExtra.mimeType="video/x-mp4"; //init Qiniu_Client_InitMacAuth(&client, 1024, &mac); Qiniu_Error error = Qiniu_Rio_PutFile(&client, &putRet, uptoken, key, localFile, &putExtra); if (error.code != 200) { printf("upload file %s:%s error.\n", bucket, key); debug_log(&client, error); } else { /*200, 正确返回了, 你可以通过statRet变量查询一些关于这个文件的信息*/ printf("upload file %s:%s success.\n\n", bucket, key); printf("key:\t%s\n", putRet.key); printf("hash:\t%s\n", putRet.hash); } Qiniu_Free(uptoken); Qiniu_Client_Cleanup(&client); }
static void clientIoPutBuffer(const char* uptoken) { Qiniu_Error err; Qiniu_Client client; Qiniu_Rio_PutExtra extra; Qiniu_Rio_PutRet putRet; Qiniu_Seq seq; Qiniu_ReaderAt in; Qiniu_Int64 fsize = testFsize; Qiniu_Client_InitNoAuth(&client, 1024); Qiniu_Zero(extra); extra.bucket = bucket; extra.notify = notify; extra.notifyErr = notifyErr; extra.chunkSize = 1024; in = Qiniu_SeqReaderAt(&seq, fsize, 10, '0', 0); err = Qiniu_Rio_Put(&client, &putRet, uptoken, key, in, fsize, &extra); printf("\n%s", Qiniu_Buffer_CStr(&client.respHeader)); printf("hash: %s\n", putRet.hash); CU_ASSERT(err.code == 200); CU_ASSERT_STRING_EQUAL(putRet.hash, "FoErrxvY99fW7npWmVii0RncWKme"); Qiniu_Client_Cleanup(&client); }
int main(int argc, char **argv) { Qiniu_Client client; Qiniu_CDN_RefreshRet ret; Qiniu_Error error; char **p; int i; char *accessKey = getenv("QINIU_ACCESS_KEY"); char *secretKey = getenv("QINIU_SECRET_KEY"); Qiniu_Mac mac; mac.accessKey = accessKey; mac.secretKey = secretKey; //urls to refresh char *urls[] = { "http://csdk.qiniudn.com/qiniu1.png", "http://csdk.qiniudn.com/qiniu2.png", "http://csdk.qiniudn.com/qiniu3.png" }; //init Qiniu_Zero(ret); Qiniu_Client_InitMacAuth(&client, 1024, &mac); error = Qiniu_CDN_RefreshUrls(&client, &ret, urls, 3); if (error.code != 200) { printf("refresh urls error.\n"); debug_log(&client, error); } else { printf("refresh urls success.\n"); printf("Code: %d\n", ret.code); printf("Error: %s\n", ret.error); printf("RequestId: %s\n", ret.requestId); p = ret.invalidUrls; for (i = 0; i < ret.invalidUrlsCount; i++) { printf("InvalidUrl: %s\n", *p); ++p; } p = ret.invalidDirs; for (i = 0; i < ret.invalidDirsCount; i++) { printf("InvalidDir: %s\n", *p); ++p; } printf("UrlQuotaDay: %d\n", ret.urlQuotaDay); printf("UrlSurplusDay: %d\n", ret.urlSurplusDay); printf("DirQuotaDay: %d\n", ret.dirQuotaDay); printf("DirSurplusDay: %d\n", ret.dirSurplusDay); Qiniu_Free_CDNRefreshRet(&ret); } Qiniu_Client_Cleanup(&client); }
int GetUploadToken(char *pBuf, int nBufLen) { #ifdef DISABLE_OPENSSL memset(pBuf, 0, nBufLen); CURL *curl; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "http://39.107.247.14:8086/qiniu/upload/token"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); struct CurlToken token; token.pData = pBuf; token.nDataLen = nBufLen; token.nCurlRet = 0; curl_easy_setopt(curl, CURLOPT_WRITEDATA, &token); int ret =curl_easy_perform(curl); if (ret != 0) { curl_easy_cleanup(curl); return ret; } curl_easy_cleanup(curl); return token.nCurlRet; #else if (gAk[0] == 0 || gSk[0] == 0 || gBucket[0] == 0) return -11; memset(pBuf, 0, nBufLen); Qiniu_Mac mac; mac.accessKey = gAk; mac.secretKey = gSk; Qiniu_RS_PutPolicy putPolicy; Qiniu_Zero(putPolicy); putPolicy.scope = gBucket; putPolicy.expires = 40; putPolicy.deleteAfterDays = 7; putPolicy.callbackBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":$(fsize),\"bucket\":\"$(bucket)\",\"name\":\"$(x:name)\",\"duration\":\"$(avinfo.format.duration)\"}"; putPolicy.callbackUrl = CALLBACK_URL; putPolicy.callbackBodyType = "application/json"; char *uptoken; uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, &mac); assert(nBufLen > strlen(uptoken)); strcpy(pBuf, uptoken); Qiniu_Free(uptoken); return 0; #endif }
static void clientIoPutFile(const char* uptoken) { Qiniu_Error err; Qiniu_Client client; Qiniu_Io_PutExtra extra; Qiniu_Io_PutRet putRet; Qiniu_Client_InitNoAuth(&client, 1024); Qiniu_Zero(extra); extra.bucket = bucket; err = Qiniu_Io_PutFile(&client, &putRet, uptoken, key, __FILE__, &extra); CU_ASSERT(err.code == 200); printf("\n%s\n", Qiniu_Buffer_CStr(&client.respHeader)); printf("hash: %s\n", putRet.hash); Qiniu_Client_Cleanup(&client); }
static void clientIoPutBuffer(const char* uptoken) { const char text[] = "Hello, world!"; Qiniu_Error err; Qiniu_Client client; Qiniu_Io_PutExtra extra; Qiniu_Io_PutRet putRet; Qiniu_Client_InitNoAuth(&client, 1024); Qiniu_Zero(extra); extra.bucket = bucket; err = Qiniu_Io_PutBuffer(&client, &putRet, uptoken, key, text, sizeof(text)-1, &extra); printf("\n%s", Qiniu_Buffer_CStr(&client.respHeader)); printf("hash: %s\n", putRet.hash); CU_ASSERT(err.code == 200); CU_ASSERT_STRING_EQUAL(putRet.hash, "FpQ6cC0G80WZruH42o759ylgMdaZ"); Qiniu_Client_Cleanup(&client); }
int main(int argc, char * argv[]) { Qiniu_Client client; Qiniu_Mac mac; char * bucketName = "test"; char * file_path = "./local.txt"; mac.accessKey = "Hw_2_emX0FV5fe26brBCemk3Yhdzd5l86UwfI9_n"; mac.secretKey = "V09N6hmt3Z4vieC7Ps3g6HAyQ136cGSmAj7UtjWv"; Qiniu_Servend_Init(-1); Qiniu_Client_InitNoAuth(&client, 1024); #if 0 //upload Qiniu_RS_PutPolicy putPolicy; Qiniu_Zero(putPolicy); putPolicy.scope = "test"; char * uploadtoken = Qiniu_RS_PutPolicy_Token(&putPolicy, &mac); Qiniu_Io_PutRet putRet; Qiniu_Error error = Qiniu_Io_PutFile(&client, &putRet, uploadtoken, "local.txt", "./local.txt", NULL); if (error.code != 200) { printf("!200 ERROR\n"); } else { printf("200 OK\n"); } Qiniu_Free(uploadtoken); #endif #if 1 //download Qiniu_RS_GetPolicy getPolicy; Qiniu_Zero(getPolicy); //char* domain = Qiniu_String_Concat2("heenbo-test", "o9mmpvxgk.bkt.clouddn.com"); char* domain = Qiniu_String_Concat2("", "o9mmpvxgk.bkt.clouddn.com"); printf("domain:%s\n", domain); char * baseUrl = Qiniu_RS_MakeBaseUrl(domain, "a.txt"); printf("baseUrl: %s\n", baseUrl); char * url = Qiniu_RS_GetPolicy_MakeRequest(&getPolicy, baseUrl, &mac); printf("url:%s\n", url); Qiniu_Free(baseUrl); Qiniu_Free(url); Qiniu_Free(domain); #endif Qiniu_Client_Cleanup(&client); Qiniu_Servend_Cleanup(); return 0; }
int main(int argc, char **argv) { Qiniu_Client client; Qiniu_CDN_FluxRet ret; Qiniu_Error error; int i, j; char *accessKey = getenv("QINIU_ACCESS_KEY"); char *secretKey = getenv("QINIU_SECRET_KEY"); Qiniu_Mac mac; mac.accessKey = accessKey; mac.secretKey = secretKey; //urls to refresh char *domains[] = { "csdk.qiniudn.com", "javasdk.qiniudn.com" }; int domainsCount = 2; char *startDate = "2017-08-01"; char *endDate = "2017-08-09"; char *g = "day"; //init Qiniu_Zero(ret); Qiniu_Client_InitMacAuth(&client, 1024, &mac); error = Qiniu_CDN_GetFluxData(&client, &ret, startDate, endDate, g, domains, domainsCount); if (error.code != 200) { printf("get domain flux error.\n"); debug_log(&client, error); } else { printf("get domain flux success.\n\n"); printf("Code: %d\n", ret.code); printf("Error: %s\n", ret.error); printf("Domains: %d\n", ret.domainsCount); printf("-----------\n"); for (i = 0; i < ret.timeCount; i++) { printf("%s\t", ret.time[i]); } printf("\n"); //data for (i = 0; i < ret.domainsCount; i++) { printf("Domain:%s\n", domains[i]); Qiniu_CDN_FluxData fluxData = ret.data[i]; if (fluxData.chinaCount == 0) { printf("China: no flux data\n"); } else { printf("China: flux data\n"); for (j = 0; j < fluxData.chinaCount; j++) { printf("%lld\t", fluxData.china[j]); } printf("\n"); } if (fluxData.overseaCount == 0) { printf("Oversea: no flux data\n"); } else { printf("Oversea: flux data\n"); for (j = 0; j < fluxData.overseaCount; j++) { printf("%lld\t", fluxData.oversea[j]); } printf("\n"); } printf("-----------\n"); } Qiniu_Free_CDNFluxRet(&ret); } Qiniu_Client_Cleanup(&client); }