Sample code for 30+ languages & platforms
Swift

S3 Upload File

See more Amazon S3 Examples

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 API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!

    // Insert your AWS keys here:
    http.awsAccessKey = "AWS_ACCESS_KEY"
    http.awsSecretKey = "AWS_SECRET_KEY"

    var bucketName: String? = "chilkat.ocean"
    var objectName: String? = "seahorse.jpg"
    var localFilePath: String? = "qa_data/jpg/seahorse.jpg"

    // The Content-Type has the form  type/subtype, such as application/pdf, application/json, image/jpeg, etc.
    // See Explaining Content-Types
    var contentType: String? = "image/jpeg"

    success = http.s3_UploadFile(localFilePath: localFilePath, contentType: contentType, bucketName: bucketName, objectName: objectName)

    if success != true {
        print("\(http.lastErrorText!)")
    }
    else {
        print("File uploaded.")
    }


}