Xbase++
Xbase++
S3 Upload a File with Public Read Permissions
See more Amazon S3 Examples
Demonstrates how to upload a file to the Amazon S3 service with the x-amz-acl request header set to "public-read" to allow the file to be publicly downloadable.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cBucketName
LOCAL cObjectName
LOCAL cLocalFilePath
LOCAL cContentType
nSuccess := 0
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Insert your AWS keys here:
oHttp:AwsAccessKey := "AWS_ACCESS_KEY"
oHttp:AwsSecretKey := "AWS_SECRET_KEY"
cBucketName := "chilkat.ocean"
cObjectName := "seahorse.jpg"
cLocalFilePath := "qa_data/jpg/seahorse.jpg"
cContentType := "image/jpg"
// Add the x-amz-acl request header to make the file publicly readable.
oHttp:SetRequestHeader("x-amz-acl", "public-read")
nSuccess := oHttp:S3_UploadFile(cLocalFilePath, cContentType, cBucketName, cObjectName)
IF (nSuccess != 1)
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
IF (oHttp:LastStatus == 200)
? "File uploaded."
ELSE
? "Response status code: " + Str(oHttp:LastStatus)
? oHttp:LastResponseBody
ENDIF
oHttp:destroy()