Amazon AWS woes ...

Please post the simplest of examples of using ColdFusion to post files to the S3.amazonaws.com server using an HTML5 PLUpload interface like the tutorial posted below.

Here is a link to a demo / tutorial that I referred to:
https://github.com/moxiecode/plupload/wiki/Upload-to-Amazon-S3

BTW - I get 403 forbidden ...
LVL 25
dgrafxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RickEpnetCommented:
What version of coldfusion are you using?
0
dgrafxAuthor Commented:
sorry forgot to add that - 8
0
RickEpnetCommented:
That makes it a bit harder. They started including some AWS things in 10 I would not know how to do that in 8 maybe someone else does. Click request attention.
0
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

_agx_Commented:
I can't test it, but the only parts that look php specific are generating the "policy" and "signature" values. It's just some hashing and base64 encoding so you should be able to do the same in CF8. Once you have got the values, I think it's just a matter of plugging in 4 CF variables instead of php variables here:

  
    url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
    ..
    multipart_params: {
       ...
        'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',       
        'policy': '<?php echo $policy; ?>',
        'signature': '<?php echo $signature; ?>'
    }

Open in new window



Edit:  There's a CF example of doing the same thing (just with a plain form post) here.


One question, does CF8 support nesting of implicit arrays and structures? I can't remember. Run this code, does it work or error out?

<cfscript>
	aaaa = {
		"bbbb"   = "test..."
		, "cccc" = [ {"ddd" = "123"}, { "eee" = "abcd"}]
	};
</cfscript>
						
<cfdump var="#aaaa#">

Open in new window

0
dgrafxAuthor Commented:
that code errors - i had to rewrite some cfscript algorithm code into tag based code for the encryption for that same reason.

I will post back - I had a new idea I wanted to try this morning but ran into network issues ...
0
_agx_Commented:
Don't know if you figured it out, but I think I converted this example to CF8 syntax.  Only 2 things are unsupported:  hmac (cf10+) and nested {} and [].

For HMAC() you'll need a custom function like this one.  (Didn't have time to convert it all to cfscript. ) The rest is just breaking out the structures an arrays into single lines:

HMACEncrypt
<cffunction name="hmacEncrypt" returntype="binary" access="public" output="false">
   <cfargument name="signKey" type="string" required="true" />
   <cfargument name="signMessage" type="string" required="true" />
   <cfargument name="algorithm" type="string" default="HmacSHA1" />
   <cfargument name="charset" type="string" default="UTF-8" />

   <cfset var msgBytes = charsetDecode(arguments.signMessage, arguments.charset) />
   <cfset var keyBytes = charsetDecode(arguments.signKey, arguments.charset) />
   <cfset var keySpec = createObject("java","javax.crypto.spec.SecretKeySpec")  />
   <cfset var mac = createObject("java","javax.crypto.Mac") />

   <cfset key = keySpec.init(keyBytes, arguments.algorithm) />
   <cfset mac = mac.getInstance(arguments.algorithm) />
   <cfset mac.init(key) />
   <cfset mac.update(msgBytes) />

   <cfreturn mac.doFinal() />
</cffunction>

Open in new window



Generate policy and signature:

<cfscript>
	// Hard coded for demo purposes only 
	aws.bucket = "your bucket here";
 	aws.secretKey = "secret key here";
 	aws.accessId = "your id here";
	successUrl = "http://" & cgi.server_name & getDirectoryFromPath( cgi.script_name ) & "success.cfm";
 

	// CF8 does not support nesting of {} and [], so build array the long way
	conditions = [];	

	// append structures
	data = {"bucket" = aws.bucket};
	arrayAppend(conditions, data);
	data = { "acl" = "private"};
	arrayAppend(conditions, data);
	data = {"success_action_redirect" = successUrl};
	arrayAppend(conditions, data);
	
	// append arrays
	data = [ "starts-with", "$key", "/form-post/" ];
	arrayAppend(conditions, data);
	data = [ "starts-with", "$Content-Type", "image/" ];
	arrayAppend(conditions, data);
	data = [ "content-length-range", 0, 10485760 ];
	arrayAppend(conditions, data);
	
	policy = {
		"expiration"   = dateFormat( expiration, "yyyy-mm-dd" ) & "T" & timeFormat( expiration, "HH:mm:ss" ) & "Z" 
		, "conditions" = conditions
	};
	 

	serializedPolicy = serializeJson( policy );
	serializedPolicy = reReplace( serializedPolicy, "[\r\n]+", "", "all" );
	encodedPolicy = binaryEncode(charsetDecode( serializedPolicy, "utf-8" ) ,"base64");
	// Custom function for CF8
	// http://stackoverflow.com/a/2960258
	hashedPolicy = hmacEncrypt(aws.secretKey,encodedPolicy,"HmacSHA1","utf-8");
	encodedSignature = binaryEncode(hashedPolicy, "base64");
	
	//WriteDump(policy);
	//writeDump(encodedSignature);
</cfscript>

Open in new window


After that you should be able to just plug the CF variables into the config section

<cfoutput>
...
url : 'http://#aws.bucket#.s3.amazonaws.com/',
    ..
    multipart_params: {
       ...
        'AWSAccessKeyId' : '#aws.accessId#',       
        'policy': '#encodedPolicy#',
        'signature': '#encodedSignature#'
    }	
...	
</cfoutput>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgrafxAuthor Commented:
will get back to you - really swamped with "stuff" ...
I do appreciate it!
0
dgrafxAuthor Commented:
sorry for the delay - it took me a while to get back to this ...

as it turns out the issue with my code was a secondary process which encodes the uploaded video.
i was shocked to discover that the file was arriving to amazon and that the error was occurring after that.
i originally thought that i had a connection error to amazon - because of the error message.

thanks and the code posted is pretty much the same as what I'm using for those of you reading this post.
0
_agx_Commented:
Ugh.. the joys of troubleshooting processes involving remote servers. Glad you finally figured it out!
0
dgrafxAuthor Commented:
Yes - joys - I like that ...
0
dgrafxAuthor Commented:
_agx_ - here are some more points for ya (potentially anyway) ...

http://www.experts-exchange.com/Programming/Languages/Scripting/Cold_Fusion_Markup_Language/Q_28521522.html

Thanks
0
_agx_Commented:
Hey.  Won't be able to look it over till tomorrow. But have you looked at the zencoder project on riaforge? I only skimmed the example, but .. looks like it works with S3.

https://github.com/sctm/zencoder-cf/tree/master/examples
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.