(Go) Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := chilkat.NewHttp()
http.SetAwsAccessKey("AWS_ACCESS_KEY")
http.SetAwsSecretKey("AWS_SECRET_KEY")
bucketName := "chilkat.qa"
objectName := "images/sea_creatures/starfish.jpg"
localFilePath := "qa_data/jpg/starfish.jpg"
contentType := "image/jpg"
jpgData := chilkat.NewBinData()
success := jpgData.LoadFile(localFilePath)
if !success {
fmt.Println("Failed to load ", localFilePath)
http.DisposeHttp()
jpgData.DisposeBinData()
return
}
var jpgBytes []byte
jpgBytes = jpgData.GetBinary()
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName)
if success != true {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
jpgData.DisposeBinData()
return
}
fmt.Println("Success. File uploaded.")
http.DisposeHttp()
jpgData.DisposeBinData()
|