...
The Amazon S3 Module provides two functions and one two actions.
getValue function
...
Code Block | ||
---|---|---|
| ||
rule upload is active { select when pageview ".*" setting () pre { text = "This is a test upload"; } { AWSS3:upload("kynetx_example", "kynetx_example_upload.txt", text); } } |
...
Using the base64 functions, we can also upload images. Do it, like so:
Code Block | ||||
---|---|---|---|---|
| ||||
rule upload is active { select when pageview ".*" setting () pre { image = << data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA UAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB KE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg== >>; } { AWSS3:upload("kynetx_example", "testuploaddata.png", this2that:base642string(AWSS3:getValue(image))) with object_type = AWSS3:getType(image); } } |
del action
The delete action takes two parameters, the bucket
and the object_name
.
The bucket is a string. This string should contain the name of the Amazon S3 bucket to delete the file from.
The object_name is a string. This string is the name the file to delete.
As well as having these three parameters, you can also configure the upload action with the following options:
- object_type
- This option is the mimetype of the file you are delete.
- acl
- This option is the same as the Amazon ACL. It defaults to "public-read"
Since these values are used to calculate the ACL authorization string, they must be correct.
Code Block | ||
---|---|---|
| ||
rule upload is active {
select when pageview ".*" setting ()
{
AWSS3:del("kynetx_example", "kynetx_example_upload.txt");
}
} |
Example Ruleset
Code Block | ||
---|---|---|
| ||
ruleset a41x175 { meta { name "TestAmazonS3Module" description << TestAmazonS3Module >> author "Jessie A. Morris" // Uncomment this line to require Marketplace purchase to use this app. // authz require user logging on key aws { "AWSAccessKey": "YOURACCESSKEYHERE", "AWSSecretKey": "YOURSECRETKEYHERE" } use module a41x174 alias AWSS3 with AWSKeys = keys:aws() } dispatch { // Some example dispatch domains // domain "example.com" // domain "other.example.com" } global { image = << data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA UAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB KE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg== >>; } rule getValue is active { select when pageview ".*" setting () pre { base64EncodedData = AWSS3:getValue(image); } noop(); } rule getType is active { select when pageview ".*" setting () pre { mimetype = AWSS3:getType(image); } noop(); } rule upload is active { select when pageview ".*" setting () pre { text = "This is a test upload"; } { AWSS3:upload("jessiemorristest", "testuploaddata.png", this2that:base642string(AWSS3:getValue(image)) ) with object_type = AWSS3:getType(image); } } } |