(C++) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
#include <CkHttp.h>
#include <CkBinData.h>
#include <CkByteData.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
http.put_AwsAccessKey("AWS_ACCESS_KEY");
http.put_AwsSecretKey("AWS_SECRET_KEY");
const char *bucketName = "chilkat.qa";
const char *objectName = "images/sea_creatures/starfish.jpg";
const char *localFilePath = "qa_data/jpg/starfish.jpg";
const char *contentType = "image/jpg";
CkBinData jpgData;
bool success = jpgData.LoadFile(localFilePath);
if (!success) {
std::cout << "Failed to load " << localFilePath << "\r\n";
return;
}
CkByteData jpgBytes;
success = jpgData.GetBinary(jpgBytes);
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName);
if (success != true) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
std::cout << "Success. File uploaded." << "\r\n";
}
|