Created
December 16, 2021 11:57
-
-
Save nb312/fc351c621d8a2fcba19ad7fcea83aa44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
InitializeSdk(); | |
string acessKey = "LTAI4FdgRS23ETv1LfqSsyVS"; | |
string secret = "LNJGNlhmp9B7oE090cydWPuGGiczMQ"; | |
string endpoint = "oss-cn-shanghai.aliyuncs.com"; | |
string bucket = "room-20211208"; | |
FString filePath = FPaths::ProjectContentDir(); | |
string path(TCHAR_TO_UTF8(*filePath)); | |
ClientConfiguration conf; | |
/* 设置连接池数,默认为16个。*/ | |
conf.maxConnections = 20; | |
/* 设置请求超时时间,超时没有收到数据就关闭连接,默认为10000ms。*/ | |
conf.requestTimeoutMs = 8000; | |
OssClient client(endpoint, acessKey, secret, conf); | |
/* 填写文件完整路径,例如exampledir/exampleobject.txt。文件完整路径中不能包含Bucket名称 */ | |
string ObjectName = "text1.txt"; | |
/* 填写本地文件完整路径,例如D:\\localpath\\examplefile.txt,其中localpath为本地文件examplefile.txt所在本地路径 */ | |
string FileNametoSave = path+"Test/text1.txt"; | |
//GetObjectRequest request(bucket, ObjectName); | |
// request.setResponseStreamFactory([=]() {return std::make_shared<std::fstream>(FileNametoSave, std::ios_base::out | std::ios_base::in | std::ios_base::trunc | std::ios_base::binary); }); | |
//request.setResponseStreamFactory([=]() {return std::make_shared<std::fstream>(FileNametoSave, std::ios_base::out | std::ios_base::in | std::ios_base::trunc | std::ios_base::binary); }); | |
//auto outcome = client.GetObject(request); | |
GetObjectOutcome outcome = client.GetObject(bucket,ObjectName, FileNametoSave); | |
if (outcome.isSuccess() !=true ) { | |
cout << "failed" << endl; | |
ShutdownSdk(); | |
return "failed"; | |
} | |
else { | |
cout << "success" << endl; | |
} | |
ShutdownSdk(); | |
return path; | |
} | |
catch (std::exception e) { | |
cout << "exception: %s" << "exception" << endl; | |
return "exception"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment