(Swift) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
func chilkatTest() {
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
http.awsAccessKey = "AWS_ACCESS_KEY"
http.awsSecretKey = "AWS_SECRET_KEY"
var bucketName: String? = "chilkat.qa"
var objectName: String? = "images/sea_creatures/starfish.jpg"
var localFilePath: String? = "qa_data/jpg/starfish.jpg"
var contentType: String? = "image/jpg"
let jpgData = CkoBinData()!
var success: Bool = jpgData.loadFile(localFilePath)
if !success {
print("Failed to load \(localFilePath!)")
return
}
var jpgBytes: NSData
jpgBytes = jpgData.getBinary()
success = http.s3_UploadBytes(jpgBytes, contentType: contentType, bucketName: bucketName, objectName: objectName)
if success != true {
print("\(http.lastErrorText!)")
return
}
print("Success. File uploaded.")
}
|