(Unicode C++) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
#include <CkHttpW.h>
#include <CkBinDataW.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.
CkHttpW http;
http.put_AwsAccessKey(L"AWS_ACCESS_KEY");
http.put_AwsSecretKey(L"AWS_SECRET_KEY");
const wchar_t *bucketName = L"chilkat.qa";
const wchar_t *objectName = L"images/sea_creatures/starfish.jpg";
const wchar_t *localFilePath = L"qa_data/jpg/starfish.jpg";
const wchar_t *contentType = L"image/jpg";
CkBinDataW jpgData;
bool success = jpgData.LoadFile(localFilePath);
if (!success) {
wprintf(L"Failed to load %s\n",localFilePath);
return;
}
CkByteData jpgBytes;
success = jpgData.GetBinary(jpgBytes);
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName);
if (success != true) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"Success. File uploaded.\n");
}
|