Sample code for 30+ languages & platforms
Swift

Backblaze S3 Upload Binary

See more Backblaze S3 Examples

Demonstrates how to upload the in-memory binary data to an Backblaze bucket.

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()!

    // keyID = Access Key ID or Access Key
    http.awsAccessKey = "access-key"

    // applicationKey = Secret Access Key or Secret Key
    http.awsSecretKey = "secret-key"

    // Region is the 2nd part of your S3 Endpoint
    http.awsEndpoint = "s3.us-west-002.backblazeb2.com"

    var bucketName: String? = "chilkat-test-123"
    var objectName: String? = "starfish.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"

    http.keepResponseBody = true

    let jpgData = CkoBinData()!
    success = jpgData.loadFile(path: "qa_data/jpg/starfish.jpg")

    success = http.s3_UploadBd(bd: jpgData, contentType: contentType, bucketPath: bucketName, objectName: objectName)
    if success != true {
        print("\(http.lastErrorText!)")

        let xml = CkoXml()!
        xml.load(xmlData: http.lastResponseBody)
        print("\(xml.getXml()!)")
    }
    else {
        print("JPG uploaded.")
    }


}