分享

aws sdk cpp中S3相关的应用和示例 | ictfox blog

 码农书馆 2021-01-20
/*
* Put one file slice to s3 object
*/
int S3Storage::put_object_from_file_slice(const S3Client &client,
const Aws::String bucket,
const Aws::String object,
const string &file_name,
const uint64_t offset,
const uint64_t length)
{
...
// Upload file with slices to s3 paralleled
PutObjectRequest request;
request.WithKey(object).WithBucket(bucket);

Aws::FStream local_file;
local_file.open(file_name.c_str(), std::ios::in | std::ios::binary);
assert(local_file.good());

Array<uint8_t> file_contents(length);
local_file.seekg(offset, std::ios::beg);
cout << "file read offset " << local_file.tellg() << endl;
local_file.read((char*)file_contents.GetUnderlyingData(),
file_contents.GetLength());
local_file.close();

//set the stream that will be put to s3
auto sbuff = Aws::New<Aws::Utils::Stream::PreallocatedStreamBuf>(CLASS_TAG,
&file_contents, file_contents.GetLength());
auto sbody = Aws::MakeShared<Aws::IOStream>("whatever string", sbuff);
request.SetBody(sbody);

auto outcome = client.PutObject(request);
if(outcome.IsSuccess()) {
cout << "Put object succeeded!" << endl;
} else {
cout << "PutObject error: " <<
outcome.GetError().GetExceptionName() << " - " <<
outcome.GetError().GetMessage() << endl;
}
...
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多