int saveas(QBox_Client* client) { QBox_Error err; QBox_RS_GetRet getRet; QBox_RS_PutRet putRet; QBox_IMG_SaveAsRet ret; QBox_IMG_MogrOpts opts; QBox_IMG_InitMogrOpts(&opts); char* imgURL = NULL; err = QBox_RS_PutFile(client, &putRet, TABLE, "gogopher.jpg", "image/jpeg", "gogopher.jpg", ""); QBT_CheckErr(err); err = QBox_RS_Get(client, &getRet, TABLE, "gogopher.jpg", NULL); QBT_CheckErr(err); imgURL = (char*)malloc(strlen(getRet.url)*sizeof(char)); strcpy(imgURL, getRet.url); err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save1"); QBT_CheckErr(err); opts.auto_orient = 1; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save2"); QBT_CheckErr(err); opts.quality = "60"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save3"); QBT_CheckErr(err); opts.thumbnail = "!120x120r"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save4"); QBT_CheckErr(err); opts.gravity = "North"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save5"); QBT_CheckErr(err); opts.crop = "!300x400a10a10"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save6"); QBT_CheckErr(err); opts.rotate = "45"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save7"); QBT_CheckErr(err); opts.format = "png"; err = QBox_IMG_SaveAs(client, &ret, &opts, imgURL, TABLE, "save8"); QBT_CheckErr(err); free(imgURL); return 0; }
int main() { QBox_Error err; QBox_Token* token; QBox_Client client; QBox_RS_PutAuthRet putAuthRet; QBox_RS_PutRet putRet; QBox_RS_GetRet getRet; QBox_RS_StatRet statRet; char* hash; QBox_Zero(client); QBox_Global_Init(-1); printf("QBox_Token_ExchangeByPassword\n"); err = QBox_Token_ExchangeByPassword(&token, "*****@*****.**", "test"); if (err.code != 200) { printf("QBox_Token_ExchangeByPassword failed: %d - %s\n", err.code, err.message); goto lzDone; } QBox_Client_InitByPassword(&client, token, 1024); QBox_Token_Release(token); QBox_RS_Delete(&client, "Bucket", "rs_demo.c"); printf("QBox_RS_PutFile\n"); err = QBox_RS_PutFile(&client, &putRet, "Bucket", "rs/demo.c", "application/octet-stream", __FILE__, ""); if (err.code != 200) { printf("QBox_RS_PutFile failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Get\n"); err = QBox_RS_Get(&client, &getRet, "Bucket", "rs/demo.c", NULL); if (err.code != 200) { printf("QBox_RS_Get failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_PutAuth\n"); err = QBox_RS_PutAuth(&client, &putAuthRet); if (err.code != 200) { printf("QBox_RS_PutAuth failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RSCli_PutFile\n"); err = QBox_RSCli_PutFile(NULL, putAuthRet.url, "Bucket", "rs_demo.c", "application/octet-stream", __FILE__, "", "key=rs_demo.c"); if (err.code != 200) { printf("QBox_RS_PutFile failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Get\n"); err = QBox_RS_Get(&client, &getRet, "Bucket", "rs_demo.c", NULL); if (err.code != 200) { printf("QBox_RS_Get failed: %d - %s\n", err.code, err.message); goto lzDone; } hash = strdup(getRet.hash); printf("QBox_RS_GetIfNotModified: %s\n", hash); err = QBox_RS_GetIfNotModified(&client, &getRet, "Bucket", "rs_demo.c", NULL, hash); free(hash); if (err.code != 200) { printf("QBox_RS_GetIfNotModified failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Stat\n"); err = QBox_RS_Stat(&client, &statRet, "Bucket", "rs_demo.c"); if (err.code != 200) { printf("QBox_RS_Stat failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Publish\n"); err = QBox_RS_Publish(&client, "Bucket", "iovip.qbox.me/Bucket"); if (err.code != 200) { printf("QBox_RS_Publish failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Unpublish\n"); err = QBox_RS_Unpublish(&client, "iovip.qbox.me/Bucket"); if (err.code != 200) { printf("QBox_RS_Unpublish failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Delete\n"); err = QBox_RS_Delete(&client, "Bucket", "rs_demo.c"); if (err.code != 200) { printf("QBox_RS_Delete failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Drop\n"); err = QBox_RS_Drop(&client, "Bucket"); if (err.code != 200) { printf("QBox_RS_Drop failed: %d - %s\n", err.code, err.message); goto lzDone; } lzDone: QBox_Client_Cleanup(&client); QBox_Global_Cleanup(); return 0; }
void put_blocks(const char* fl) { QBox_Error err; QBox_Client client; QBox_Client client2; QBox_AuthPolicy auth; QBox_ReaderAt f; QBox_UP_PutRet putRet; QBox_RS_GetRet getRet; char* uptoken = NULL; char* entry = NULL; QBox_Json* root = NULL; QBox_UP_Progress* prog = NULL; QBox_Int64 fsize = 0; printf("Processing ... %s\n", fl); /* Delete old file */ QBox_Zero(client2); QBox_Client_Init(&client2, 1024); printf("QBox_RS_Delete\n"); QBox_RS_Delete(&client2, "Bucket", fl); /* Upload file */ QBox_Zero(client); QBox_Zero(auth); /* QBox_MakeUpToken() should be called on Biz-Server side */ printf("QBox_MakeUpToken\n"); uptoken = QBox_MakeUpToken(&auth); if (uptoken == NULL) { printf("Cannot generate UpToken!\n"); return; } /* QBox_Client_InitByUpToken() and * other QBox_UP_xxx() functions should be called on Up-Client side */ printf("QBox_Client_InitByUpToken\n"); QBox_Client_InitByUpToken(&client, uptoken, 1024); f = QBox_FileReaderAt_Open(fl); if ((int)f.self >= 0) { fsize = (QBox_Int64) lseek((int)f.self, 0, SEEK_END); prog = QBox_UP_NewProgress(fsize); printf("QBox_RS_ResumablePut\n"); entry = QBox_String_Concat("Bucket:", fl, NULL); err = QBox_RS_ResumablePut( &client, &putRet, prog, NULL, /* blockNotify */ NULL, /* chunkNotify */ NULL, /* notifyParams */ entry, "text/plain", f, fsize, NULL, /* customMeta */ NULL /* callbackParams */ ); free(entry); QBox_FileReaderAt_Close(f.self); if (err.code != 200) { printf("QBox_RS_ResumablePut failed: %d - %s\n", err.code, err.message); free(uptoken); return; } QBox_UP_Progress_Release(prog); /* Check uploaded file */ printf("QBox_RS_Get\n"); err = QBox_RS_Get(&client2, &getRet, "Bucket", fl, NULL); if (err.code != 200) { printf("QBox_RS_Get failed: %d - %s\n", err.code, err.message); free(uptoken); return; } printf("Got url=[%s]\n", getRet.url); printf("Got fsize=%llu\n", getRet.fsize); QBox_Client_Cleanup(&client2); } QBox_Client_Cleanup(&client); printf("\n"); }
int main() { QBox_Error err; QBox_Client client; QBox_RS_PutAuthRet putAuthRet; QBox_RS_PutRet putRet; QBox_RS_GetRet getRet; QBox_RS_StatRet statRet; char* hash; QBOX_ACCESS_KEY = "MZ0JIf9QPomOmxhvWsDh-4x5qvJ9-FdWOqEymncm"; QBOX_SECRET_KEY = "sxTWypHLCAiKilQ0IZpfvidnC2utV6b9VFX3PUyw"; QBox_Zero(client); QBox_Global_Init(-1); printf("QBox_Client_Init_ByAccessKey\n"); QBox_Client_Init(&client, 1024); QBox_RS_Delete(&client, "bucket", "rs_demo.c"); printf("QBox_RS_PutFile\n"); err = QBox_RS_PutFile(&client, &putRet, "bucket", "rs_demo.c", "application/octet-stream", __FILE__, ""); if (err.code != 200) { printf("QBox_RS_PutFile failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Get\n"); err = QBox_RS_Get(&client, &getRet, "bucket", "rs_demo.c", NULL); if (err.code != 200) { printf("QBox_RS_Get failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_PutAuth\n"); err = QBox_RS_PutAuth(&client, &putAuthRet); if (err.code != 200) { printf("QBox_RS_PutAuth failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_PutFile\n"); err = QBox_RSCli_PutFile(NULL, putAuthRet.url, "bucket", "rs_demo.c", "application/octet-stream", __FILE__, "", "key=rs_demo.c"); if (err.code != 200) { printf("QBox_RSCli_PutFile failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Get\n"); err = QBox_RS_Get(&client, &getRet, "bucket", "rs_demo.c", NULL); if (err.code != 200) { printf("QBox_RS_Get failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Get url = %s\n", getRet.url); hash = strdup(getRet.hash); printf("QBox_RS_GetIfNotModified: %s\n", hash); err = QBox_RS_GetIfNotModified(&client, &getRet, "bucket", "rs_demo.c", NULL, hash); free(hash); if (err.code != 200) { printf("QBox_RS_GetIfNotModified failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Stat\n"); err = QBox_RS_Stat(&client, &statRet, "bucket", "rs_demo.c"); if (err.code != 200) { printf("QBox_RS_Stat failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Publish\n"); err = QBox_RS_Publish(&client, "bucket", "iovip.qbox.me/Bucket"); if (err.code != 200) { printf("QBox_RS_Publish failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Unpublish\n"); err = QBox_RS_Unpublish(&client, "iovip.qbox.me/Bucket"); if (err.code != 200) { printf("QBox_RS_Unpublish failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Delete\n"); err = QBox_RS_Delete(&client, "bucket", "rs_demo.c"); if (err.code != 200) { printf("QBox_RS_Delete failed: %d - %s\n", err.code, err.message); goto lzDone; } printf("QBox_RS_Drop\n"); err = QBox_RS_Drop(&client, "bucket"); if (err.code != 200) { printf("QBox_RS_Drop failed: %d - %s\n", err.code, err.message); goto lzDone; } lzDone: QBox_Client_Cleanup(&client); QBox_Global_Cleanup(); return 0; }