Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/include/alibabacloud/oss/OssClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ namespace OSS
#ifdef USE_CORO
/*Coro APIs*/
async_simple::coro::Lazy<PutObjectOutcome> UploadPartCoro(const UploadPartRequest& request) const;
async_simple::coro::Lazy<GetObjectOutcome> GetObjectCoro(const GetObjectRequest& request) const;
#endif
/*Extended APIs*/
#if !defined(OSS_DISABLE_BUCKET)
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/OssClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ async_simple::coro::Lazy<PutObjectOutcome> OssClient::UploadPartCoro(const Uploa
{
co_return co_await client_->UploadPartCoro(request);
}

async_simple::coro::Lazy<GetObjectOutcome> OssClient::GetObjectCoro(const GetObjectRequest &request) const
{
co_return co_await client_->GetObjectCoro(request);
}
#endif

/*Extended APIs*/
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/OssClientImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,17 @@ async_simple::coro::Lazy<PutObjectOutcome> OssClientImpl::UploadPartCoro(const U
co_return PutObjectOutcome(outcome.error());
}
}

async_simple::coro::Lazy<GetObjectOutcome> OssClientImpl::GetObjectCoro(const GetObjectRequest &request) const {
auto outcome = co_await MakeRequestCoro(request, Http::Method::Get);
if (outcome.isSuccess()) {
co_return GetObjectOutcome(GetObjectResult(request.Bucket(), request.Key(),
outcome.result().payload(),outcome.result().headerCollection()));
}
else {
co_return GetObjectOutcome(outcome.error());
}
}
#endif

UploadPartCopyOutcome OssClientImpl::UploadPartCopy(const UploadPartCopyRequest &request) const
Expand Down
1 change: 1 addition & 0 deletions sdk/src/OssClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace OSS
ListPartsOutcome ListParts(const ListPartsRequest &request) const;
#ifdef USE_CORO
async_simple::coro::Lazy<PutObjectOutcome> UploadPartCoro(const UploadPartRequest& request) const;
async_simple::coro::Lazy<GetObjectOutcome> GetObjectCoro(const GetObjectRequest &request) const;
#endif

/*Generate URL*/
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/http/CoroHttpClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../utils/LogUtils.h"

namespace AlibabaCloud::OSS {
inline const char* CORO_TAG = "CurlHttpClient";
inline const char* CORO_TAG = "CoroHttpClient";

class CoroHttpClient : public HttpClient {
public:
Expand Down Expand Up @@ -53,7 +53,7 @@ class CoroHttpClient : public HttpClient {
bool has_content = (body != nullptr);
std::string content;

if (has_content) {
if (has_content && method != Http::Method::Put) {
body->seekg(0, std::ios::end);
int size = body->tellg();
content.resize(size);
Expand Down
16 changes: 15 additions & 1 deletion test/src/CoroMultipartUpload/CoroMultipartUploadPartTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CoroTest : public ::testing::Test {
BucketName = "cpp-sdk-coro";
auto outcome = Client->CreateBucket(CreateBucketRequest(BucketName));
if(outcome.isSuccess()){
std::cout << "Create Bucket "<<BucketName<<" Successfully" << std::endl;
std::cout << "Create Bucket "<<BucketName<<" Successfully" << std::endl;
}
}

Expand Down Expand Up @@ -76,6 +76,20 @@ std::string CoroTest::BucketName = "";

TEST_F(CoroTest, MultipartUploadCoroBasicTest)
{
{
std::string key = "GetObjectUsingRangeTest";
auto content = TestUtils::GetRandomStream(1024);

auto pOutcome = Client->PutObject(BucketName, key, content);
EXPECT_EQ(pOutcome.isSuccess(), true);

GetObjectRequest request(BucketName, key);
request.setRange(10, 19);
auto outome = async_simple::coro::syncAwait(Client->GetObjectCoro(request));
EXPECT_EQ(outome.isSuccess(), true);
EXPECT_EQ(outome.result().Content()->tellp(), 10);
}

auto memKey = TestUtils::GetObjectKey("MultipartUploadCoro-MemObject");
auto memContent = TestUtils::GetRandomStream(102400);
auto memInitOutcome = Client->InitiateMultipartUpload(InitiateMultipartUploadRequest(BucketName, memKey));
Expand Down