Example #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;
}
bool ossim::S3StreamBuffer::loadBlock(ossim_int64 absolutePosition)
{
   bool result = false;
   m_bufferPtr = 0;
   GetObjectRequest getObjectRequest;
   std::stringstream stringStream;
   ossim_int64 startRange, endRange;
   ossim_int64 blockIndex = getBlockIndex(absolutePosition);
   if((absolutePosition < 0) || (absolutePosition > (ossim_int64)m_fileSize)) return false;
   //std::cout << "CURRENT BYTE LOCATION = " << absoluteLocation << std::endl;
   if(getBlockRangeInBytes(blockIndex, startRange, endRange))
   {
      stringStream << "bytes=" << startRange << "-" << endRange;
      getObjectRequest.WithBucket(m_bucket.c_str())
         .WithKey(m_key.c_str()).WithRange(stringStream.str().c_str());
      auto getObjectOutcome = m_client.GetObject(getObjectRequest);

      if(getObjectOutcome.IsSuccess())
      {
//        std::cout << "GOOD CALL!!!!!!!!!!!!\n";
         Aws::IOStream& bodyStream = getObjectOutcome.GetResult().GetBody();
         ossim_int64 bufSize = getObjectOutcome.GetResult().GetContentLength();
//        std::cout << "SIZE OF RESULT ======== " << bufSize << std::endl;
         m_bufferActualDataSize = bufSize;
         bodyStream.read(&m_buffer.front(), bufSize);
         m_bufferPtr = &m_buffer.front();

         ossim_int64 delta = absolutePosition-startRange;
         setg(m_bufferPtr, m_bufferPtr + delta, m_bufferPtr+m_bufferActualDataSize);
         m_currentBlockPosition = startRange;
         result = true;
         //std::cout << "Successfully retrieved object from s3 with value: " << std::endl;
         //std::cout << getObjectOutcome.GetResult().GetBody().rdbuf() << std::endl << std::endl;;  
      }
      else
      {
         m_bufferActualDataSize = 0;
      }
   }

   return result;
}