« Our Xojo Web Apps on … | Home | PDFKit on iOS for MBS… »

Amazon S3 Upload with Mime Type and Permissions

As you may know we have functions to do authentication for Amazon WebServices in our plugins for Xojo and FileMaker. This functions can be used with various webservices from Amazon, but today we use S3 as example and upload an image from a container.

You can pass additional headers with the upload to specify permissions and content type. For example you can grant permissions to everyone with acl public-read. When you pass the content type, you get back that same content type when downloading. Here an example upload:

# Change to your own credentials, region, bucket name, file name...

Set Variable [ $AWSAccessKeyId ; Value: "AKIAK21ZENQFJ3EFLKJA" ] 

Set Variable [ $AWSSecretAccessKey ; Value: "4TMeKFtn62xDfAP6F1cENwHehRqo75kQKoT/BAKE" ] 

Set Variable [ $Region ; Value: "eu-central-1" ] 

Set Variable [ $Bucketname ; Value: "mbstest" ] 

Set Variable [ $Filename ; Value: "test.jpg" ] 

Set Variable [ $Headers ; Value: "Content-Type: image/jpeg¶x-amz-acl: public-read" ] 

Set Variable [ $Service ; Value: "s3" ] 

Set Variable [ $Verb ; Value: "PUT" ] 

# Keep those empty for default

Set Variable [ $Domain ; Value: "" ] 

Set Variable [ $HashedPayload ; Value: "" ] 

# Build a path

Set Variable [ $Path ; Value: "/" & $BucketName & "/" & $Filename ] 

# Run transfer

Set Variable [ $curl ; Value: MBS("CURL.New") ] 

Set Variable [ $result ; Value: MBS("CURL.SetInputFile"; $curl; CURL Test::Image) ] 

Set Variable [ $result ; Value: MBS("CURL.SetupAWS"; $curl; $AWSAccessKeyId; $AWSSecretAccessKey; $Region; $Service; $Path; $Domain; $Verb; ""; $Headers) ] 

Set Field [ CURL Test::Result ; MBS("CURL.Perform"; $curl) ] 

Set Field [ CURL Test::debug ; MBS("CURL.GetDebugAsText"; $curl) ] 

Set Variable [ $result ; Value: MBS("CURL.Cleanup"; $curl) ] 

Same upload works in Xojo with our MBS Xojo CURL Plugin

Please do not hesitate to contact us with questions.

30 11 17 - 17:23