Sample code for 30+ languages & platforms
Swift

Demonstrate S3_UploadBytes

Demonstrates how to upload a file to the Amazon S3 service.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // 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()!
    success = jpgData.loadFile(path: localFilePath)
    if !success {
        print("Failed to load \(localFilePath!)")
        return
    }

    var jpgBytes: NSData
    jpgBytes = jpgData.getBinary()

    success = http.s3_UploadBytes(objectContent: jpgBytes, contentType: contentType, bucketName: bucketName, objectName: objectName)
    if success != true {
        print("\(http.lastErrorText!)")
        return
    }

    print("Success. File uploaded.")

}