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

/* * 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)

相关推荐