(Swift) Demonstrate S3_DownloadBytes
Demonstrates how to download a file into memory from 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_output/starfish.jpg"
var jpgBytes: NSData
jpgBytes = http.s3_DownloadBytes(bucketName, objectName: objectName)
if http.lastMethodSuccess != true {
print("\(http.lastErrorText!)")
return
}
print("Download successful.")
let fac = CkoFileAccess()!
var success: Bool = fac.writeEntireFile(localFilePath, fileData: jpgBytes)
print("File saved success = \(success)")
}
|