(Ruby) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
require 'chilkat'
# This example assumes the Chilkat HTTP API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = Chilkat::CkHttp.new()
http.put_AwsAccessKey("AWS_ACCESS_KEY")
http.put_AwsSecretKey("AWS_SECRET_KEY")
bucketName = "chilkat.qa"
objectName = "images/sea_creatures/starfish.jpg"
localFilePath = "qa_data/jpg/starfish.jpg"
contentType = "image/jpg"
jpgData = Chilkat::CkBinData.new()
success = jpgData.LoadFile(localFilePath)
if (!success)
print "Failed to load " + localFilePath + "\n";
exit
end
jpgBytes = Chilkat::CkByteData.new()
success = jpgData.GetBinary(jpgBytes)
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName)
if (success != true)
print http.lastErrorText() + "\n";
exit
end
print "Success. File uploaded." + "\n";
|