Beispiel #1
0
int main() {
	SDKOptions options;
	options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
	Aws::InitAPI(options);

	ClientConfiguration conf = ClientConfiguration();
	conf.endpointOverride = "IPADDRESS";
	conf.verifySSL = false;
	AWSCredentials creds = AWSCredentials("ACCESS_KEY_ID", "ACCESS_KEY_SECRET");

    S3Client client = S3Client(creds, conf);

	// Put an object
	PutObjectRequest putObjectRequest;
	putObjectRequest.WithKey(KEY).WithBucket(BUCKET).WithContentEncoding("text");

	auto requestStream = Aws::MakeShared<Aws::StringStream>("s3-sample");
	*requestStream << CONTENT;
	putObjectRequest.SetBody(requestStream);
	auto putObjectOutcome = client.PutObject(putObjectRequest);
	if(putObjectOutcome.IsSuccess()) {
		std::cout << "Putting to '" << BUCKET << "/" << KEY << "' succeeded" << std::endl;
	} else {
		std::cout << "Error while putting Object " << putObjectOutcome.GetError().GetExceptionName() << 
			" " << putObjectOutcome.GetError().GetMessage() << std::endl;
		return 1;
	}

	// Retrieve the object
	GetObjectRequest getObjectRequest;
	getObjectRequest = getObjectRequest.WithBucket(BUCKET).WithKey(KEY);
	auto getObjectOutcome = client.GetObject(getObjectRequest);
	if(getObjectOutcome.IsSuccess()) {
		Aws::StringStream contents;
		contents << getObjectOutcome.GetResult().GetBody().rdbuf();

		std::cout << "Successfully retrieved '" << BUCKET << "/" << KEY << "' ";
		std::cout << "with contents: '" << contents.str() << "'" << std::endl;
		if (contents.str().compare(CONTENT) != 0 ){
			std::cout << "Retrieved content is not as expected" << std::endl;
			return 1;
		} else {
			std::cout << "Retrieved content is as expected" << std::endl;
		}
	} else {
		std::cout << "Error while getting object " << getObjectOutcome.GetError().GetExceptionName() <<
			" " << getObjectOutcome.GetError().GetMessage() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #2
0
PutObjectOutcomeCallable s3be::put_one(libbruce::be::putblock_t &block)
{
    //std::cerr << "PUT " << block.id << std::endl;
    io::basic_array_source<char> memstream((char*)block.mem.ptr(), block.mem.size());

    std::shared_ptr<std::stringstream> ss = std::make_shared<std::stringstream>();

    io::filtering_ostream in;
    in.push(io::zlib_compressor());
    in.push(*ss);
    io::copy(memstream, in);

    PutObjectRequest request;
    request.SetBucket(m_bucket);
    request.SetKey(m_prefix + boost::lexical_cast<std::string>(block.id));
    request.SetContentType("application/octet-stream");
    request.SetBody(ss);
    request.SetContentLength(ss->str().size());

    return m_s3->PutObjectCallable(request);
}