复制对象
使用 copyObject 接口拷贝某一个桶中的对象到另外一个指定的桶中。
以下代码展示如何复制某一个桶中的对象:
bool S3Demo::CopyObject()
{
const Aws::String bucket_source = s3_bucket_name;
const Aws::String bucket_dest = s3_bucket_name;
const Aws::String object_source = "ExampleObject.txt";
const Aws::String object_dest = "ExampleObject1.txt";
Aws::S3::Model::CopyObjectRequest request;
request.SetBucket(bucket_dest);
request.SetKey(object_dest);
request.SetCopySource(bucket_source + "/" + object_source); // 注意这个参数
Aws::S3::Model::CopyObjectOutcome outcome = s3_client->CopyObject(request);
if (outcome.IsSuccess()) {
std::cout << "CopyObject " << object_source << " to " << object_dest << std::endl;
return true;
}
else {
Aws::S3::S3Error err = outcome.GetError();
std::cout << "Error: CopyObject: " << (int)err.GetResponseCode() << ", Message:" <<
err.GetMessage() << std::endl;
return false;
}
}