libs/linux/libcossdk.a #linux의 정적 라이브러리libs/linux/libcossdk-shared.so #linux 동적 라이브러리libs/Win32/cossdk.lib #Win32 라이브러리libs/x64/cossdk.lib #Win64 라이브러리libs/macOS/libcossdk.a #macOS 정적 라이브러리libs/macOS/libcossdk-shared.dylib #macOS 동적 라이브러리
third_party/lib/linux/poco/ #linux에 종속된 Poco 동적 라이브러리third_party/lib/Win32/openssl/ #Win32 종속된 openssl 라이브러리third_party/lib/Win32/poco/ #Win32 종속된 poco 라이브러리third_party/lib/x64/openssl/ #Win64 종속된 openssl 라이브러리third_party/lib/x64/poco/ #Win64 종속된 poco 라이브러리third_party/lib/macOS/poco/ #macOS 종속된 poco 라이브러리
option(BUILD_UNITTEST "Build unittest" OFF) #유닛 테스트 컴파일 설정option(BUILD_DEMO "Build demo" ON) #demo 테스트 코드 컴파일 설정option(BUILD_SHARED_LIB "Build shared library" OFF) #동적 라이브러리 컴파일 설정
yum install -y gcc gcc-c++ make cmake openssl#cmake 버전 2.8 이상
cd ${cos-cpp-sdk}mkdir -p buildcd buildcmake ..make
cd ${cos-cpp-sdk}sh install-libpoco.sh
cd ${cos-cpp-sdk}vim demo/cos_demo.cpp #demo의 버킷 이름 및 테스트 코드 수정vim CMakeLists.txt #루트 디렉터리 내 CMakeLists.txt의 BUILD_DEMO를 ON으로 수정하고, 컴파일 demo 활성화cd build && make #컴파일demols bin/cos_demo #생성된 실행 가능 파일은 bin 디렉터리에 있음vim bin/config.json #키 및 단지 수정cd bin && ./cos_demo #demo 실행
libcossdk.a, 동적 라이브러리 이름은 libcossdk-shared.so입니다. 사용 시, 라이브러리는 프로그램에 복사하고 include 디렉터리는 프로그램의 include 경로에 복사하십시오.${CMake의 설치 경로}\\bin을 Windows 시스템 환경 변수 Path에 설정합니다.mkdir buildcd buildcmake .. #Win32 makefile 생성cmake -G "Visual Studio 15 Win64" .. #Win64 makefile 생성
cossdk.lib입니다. 사용 시, 라이브러리는 프로그램에 복사하고 include 디렉터리는 프로그램의 include 경로에 복사하십시오.brew install gcc make cmake openssl
cd ${cos-cpp-sdk}mkdir -p buildcd buildcmake ..make
libcossdk.a, 동적 라이브러리 이름은 libcossdk-shared.dylib입니다. 사용 시, 라이브러리는 프로그램에 복사하고, include 디렉터리는 include 경로에 복사하십시오."SecretId":"********************************", // V5.4.3 이전 버전은 AccessKey 사용"SecretKey":"*******************************","Region":"ap-guangzhou", // COS리전은 정확해야하며, 리전 및 약칭은 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1를 참고하십시오"SignExpiredTime":360, // 서명 타임아웃 시간, 단위s"ConnectTimeoutInms":6000, // connect 타임아웃 시간, 단위ms"ReceiveTimeoutInms":60000, // recv 타임아웃 시간, 단위ms"UploadPartSize":10485760, // 파일 파트 업로드 크기, 1M-5G, 기본값은 10M"UploadCopyPartSize":20971520, // 복사 파일 파트 업로드 크기, 5M-5G, 기본값은 20M"UploadThreadPoolSize":5, // 단일 파일 멀티파트 업로드 스레드 풀 크기"DownloadSliceSize":4194304, // 파일 멀티파트 다운로드 크기"DownloadThreadPoolSize":5, // 단일 파일 다운로드 스레드 풀 크기"AsynThreadPoolSize":2, // 비동기화 업로드/다운로드 스레드 풀 크기"LogoutType":1, // 로그 출력 유형, 0: 출력하지 않음, 1: 화면에 출력, 2: syslog에 출력"LogLevel":3, // 로그 레벨:1: ERR, 2: WARN, 3: INFO, 4: DBG"IsDomainSameToHost":false, // 전용 host 사용 여부"DestDomain":"", // 특정 host"IsUseIntranet":false, // 특정 ip와 포트 번호 사용 여부"IntranetAddr":"" // 특정 ip와 포트 번호, 예‘127.0.0.1:80’
"IsDomainSameToHost":true,"DestDomain":"mydomain.com",
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {qcloud_cos::CosConfig config("./config.json");// 임시 키 설정config.SetTmpToken("xxx");qcloud_cos::CosAPI cos(config);}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"void TestLogCallback(const std::string& log) {std::ofstream ofs;ofs.open("test.log", std::ios_base::app);ofs << log;ofs.close();}int main(int argc, char** argv) {qcloud_cos::CosConfig config("./config.json");config.SetLogCallback(&TestLogCallback);qcloud_cos::CosAPI cos(config);}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 버킷 생성 요청 구성std::string bucket_name = "examplebucket-1250000000"; // Bucket 이름qcloud_cos::PutBucketReq req(bucket_name);qcloud_cos::PutBucketResp resp;// 3. 버킷 생성 인터페이스 호출qcloud_cos::CosResult result = cos.PutBucket(req, &resp);// 4. 호출 결과 처리if (result.IsSucc()) {// 생성 성공} else {// 버킷 생성 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 버킷 리스트 조회 요청 구성qcloud_cos::GetServiceReq req;qcloud_cos::GetServiceResp resp;qcloud_cos::CosResult result = cos.GetService(req, &resp);// 3. 응답 정보 획득const qcloud_cos::Owner& owner = resp.GetOwner();const std::vector<qcloud_cos::Bucket>& buckets = resp.GetBuckets();std::cout << "owner.m_id=" << owner.m_id << ", owner.display_name=" << owner.m_display_name << std::endl;for (std::vector<qcloud_cos::Bucket>::const_iterator itr = buckets.begin(); itr != buckets.end(); ++itr) {const qcloud_cos::Bucket& bucket = *itr;std::cout << "Bucket name=" << bucket.m_name << ", location="<< bucket.m_location << ", create_date=" << bucket.m_create_date << std::endl;}// 4. 호출 결과 처리if (result.IsSucc()) {// 버킷 리스트 조회 성공} else {// 버킷 리스트 조회 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 파일 업로드 요청 구성std::string bucket_name = "examplebucket-1250000000"; // 업로드한 타깃 Bucket 이름std::string object_name = "exampleobject"; //exampleobject는 객체 키(Key)이며 객체의 버킷 내 고유 식별자. 예: 객체의 액세스 도메인 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg에서 객체 키는 doc/pic.jpg임// request의 생성자에 로컬 파일 경로 전달 필요qcloud_cos::PutObjectByFileReq req(bucket_name, object_name, "/path/to/local/file");req.SetXCosStorageClass("STANDARD_IA"); // Set 메소드를 호출하여 메타데이터 등을 설정qcloud_cos::PutObjectByFileResp resp;// 3. 파일 업로드 인터페이스 호출qcloud_cos::CosResult result = cos.PutObject(req, &resp);// 4. 호출 결과 처리if (result.IsSucc()) {// 파일 업로드 완료} else {// 파일 업로드 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 객체 리스트 조회 요청 구성std::string bucket_name = "examplebucket-1250000000"; // 업로드한 타깃 버킷 이름qcloud_cos::GetBucketReq req(bucket_name);qcloud_cos::GetBucketResp resp;qcloud_cos::CosResult result = cos.GetBucket(req, &resp);std::vector<qcloud_cos::Content> cotents = resp.GetContents();for (std::vector<qcloud_cos::Content>::const_iterator itr = cotents.begin(); itr != cotents.end(); ++itr) {const qcloud_cos::Content& content = *itr;std::cout << "key name=" << content.m_key << ", lastmodified ="<< content.m_last_modified << ", size=" << content.m_size << std::endl;}// 3. 호출 결과 처리if (result.IsSucc()) {// 객체 리스트 조회 성공} else {// 객체 리스트 조회 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 객체 다운로드 요청 구성std::string bucket_name = "examplebucket-1250000000"; // 업로드한 타깃 Bucket 이름std::string object_name = "exampleobject"; // exampleobject는 객체 키(Key)이며 객체의 버킷 내 고유 식별자. 예: 객체의 액세스 도메인 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg에서 객체 키는 doc/pic.jpg임.std::string local_path = "/tmp/exampleobject";// request는 appid, bucketname, object, 로컬 경로를 제공해야 함(파일 이름 포함)qcloud_cos::GetObjectByFileReq req(bucket_name, object_name, local_path);qcloud_cos::GetObjectByFileResp resp;// 3. 객체 다운로드 인터페이스 호출qcloud_cos::CosResult result = cos.GetObject(req, &resp);// 4. 호출 결과 처리if (result.IsSucc()) {// 파일 다운로드 성공} else {// 파일 다운로드 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
#include "cos_api.h"#include "cos_sys_config.h"#include "cos_defines.h"int main(int argc, char *argv[]) {// 1. 구성 파일 경로 지정, CosConfig 초기화qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);// 2. 객체 삭제 요청 구성std::string bucket_name = "examplebucket-1250000000"; // 업로드한 타깃 버킷 이름std::string object_name = "exampleobject"; // exampleobject는 객체 키(Key)이며 객체의 버킷 내 고유 식별자. 예: 객체의 액세스 도메인 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg에서 객체 키는 doc/pic.jpg임.// 3. 객체 삭제 인터페이스 호출qcloud_cos::DeleteObjectReq req(bucket_name, object_name);qcloud_cos::DeleteObjectResp resp;qcloud_cos::CosResult result = cos.DeleteObject(req, &resp);// 4. 호출 결과 처리if (result.IsSucc()) {// 객체 삭제 성공} else {// 객체 삭제 실패 시, CosResult의 멤버 함수를 호출하여 오류 정보를 출력할 수 있음(예: requestID 등)std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
피드백