(PHP ActiveX) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
<?php
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Http')
$http = new COM("Chilkat.Http");
$http->AwsAccessKey = 'AWS_ACCESS_KEY';
$http->AwsSecretKey = 'AWS_SECRET_KEY';
$bucketName = 'chilkat.qa';
$objectName = 'images/sea_creatures/starfish.jpg';
$localFilePath = 'qa_data/jpg/starfish.jpg';
$contentType = 'image/jpg';
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.BinData')
$jpgData = new COM("Chilkat.BinData");
$success = $jpgData->LoadFile($localFilePath);
if (!$success) {
print 'Failed to load ' . $localFilePath . "\n";
exit;
}
$jpgBytes = $jpgData->GetBinary();
$success = $http->S3_UploadBytes($jpgBytes,$contentType,$bucketName,$objectName);
if ($success != 1) {
print $http->LastErrorText . "\n";
exit;
}
print 'Success. File uploaded.' . "\n";
?>
|