Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Amazon S3 Module provides two three functions and two actions.

...

getType performs the exact opposite operation of getValue. Instead of returning the base64 encoded data, getType returns the mimetype of the data the data URI encoded data.

Code Block
languagejavascript
rule getType is active {
	select when pageview ".*" setting ()
	pre {
		image = <<
			data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA
			UAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB
			KE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
		>>;
		mimetype = AWSS3:getType(image);
		// Evaluates to image/png
	}
	noop();
}

makeAwsUrl(bucket, object_name)

This is a convenience function that calculates the AWS URL from a given bucket and object name. This is useful for determining where AWS stored the item and allows programmers to not hardcode URL strings in their code that might change. 

upload action

The upload action is currently the only action available in the Amazon S3 Module. It takes three parameters, the bucket, the object_name and the object_value.

...

Code Block
languagejavascript
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);


		}
	}
}

Tests

The AWSS3 module is tested by the this code.