Sample code for 30+ languages & platforms
Go

S3 Delete File

See more Amazon S3 Examples

Demonstrates how to delete a remote file (object) on the Amazon S3 service.

Chilkat Go Downloads

Go
    success := false

    // This example assumes the Chilkat HTTP API to have been previously unlocked
    // See Global Unlock Sample for sample code

    http := chilkat.NewHttp()

    // Insert your access key here
    http.SetAwsAccessKey("AWS_ACCESS_KEY")

    // Insert your secret key here
    http.SetAwsSecretKey("AWS_SECRET_KEY")

    bucketName := "chilkattest"
    objectName := "starfish.jpg"

    http.SetKeepResponseBody(true)
    success = http.S3_DeleteObject(bucketName,objectName)

    if success != true {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        return
    }

    if http.LastStatus() != 204 {
        fmt.Println("Status code = ", http.LastStatus())
        fmt.Println(http.LastResponseBody())
        fmt.Println("Failed.")
        http.DisposeHttp()
        return
    }

    // 204 is the success response status.
    // When successful, the response body will be empty.
    fmt.Println("Status code = ", http.LastStatus())
    fmt.Println("Success. Object deleted.")

    http.DisposeHttp()