<!---
Variables
INPUT:
variables.s3_target_directory, <cfset s3_target_directory = "my directory" />
variables.file_name, <cfset file_name = "my file" />
variables.file_location, <cfset file_location = "my location" />
OUTPUT:
variables.success, <cfoutput>#success#</cfoutput>
variables.transactionid / success UUID, <cfoutput>#transactionid#</cfoutput>
variables.s3_location - link can be http or https, <cfoutput>#s3_location#</cfoutput>
--->
<cftry>
<!---ACCESS KEY ID = 123456789
SECRET ACCESS ID = PASSWORD123
BUCKET NAME = cic-audio
FILE NAME = amazon_s3_test.txt--->
<cfparam name="URL.step" default="view">
<cfoutput>
<cfif URL.step eq "view">
<cfscript>
// IMPORTANT: Set your key, accesskey and bucket here
Variables.accessKeyId = "";
Variables.secretAccessKey = "";
Variables.BucketName='cic-audio'; // Put your bucket name here
// Map S3 to Joe Danziger's S3 REST Wrapper (http://amazons3.riaforge.org/)
// Place the s3.cfc in the same directory as this file
S3=createObject("component","S3"); //
Variables.RedirectURL='http://#CGI.HTTP_HOST##CGI.SCRIPT_NAME#?step=upload';
Variables.Expiration=Dateformat(DateAdd("d", 7, "#now()#"), "yyyy-mm-dd")&'T00:00:00Z'; // Expiry Date
Variables.Path='TestPath/'; // the will be put in from of every file uploaded with this form
Variables.Auth='authenticated-read'; // secure the file - you can always change this later. Set it to 'public-read' for public access
Variables.ContenType='';
Variables.Filesize=250000000; // max allowed upload size in Bytes
// Init
S3.init('#Variables.accessKeyId#','#Variables.secretAccessKey#');
</cfscript>
<h1>S3 Form POST Upload</h1>
<cfsavecontent variable="Variables.S3policy">
{"expiration": "#Variables.Expiration#",
"conditions": [
{"bucket": "#Variables.BucketName#"},
["starts-with", "$key", "#Variables.Path#"],
{"acl": "#Variables.Auth#"},
{"success_action_redirect": "#Variables.RedirectURL#"},
["starts-with", "$Content-Type", "#Variables.ContenType#"],
["content-length-range", 0, #Variables.FileSize#]
]
}
</cfsavecontent>
<cfset Variables.PolicyBase64 = ToBase64(Variables.S3policy)>
Select a file:
<form name="s3upload" id="s3upload" action="https://#Variables.BucketName#.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="#Variables.Path#${filename}">
<input type="hidden" name="AWSAccessKeyId" value="#Variables.accessKeyId#">
<input type="hidden" name="acl" value="#Variables.Auth#">
<input type="hidden" name="success_action_redirect" value="#Variables.RedirectURL#">
<input type="hidden" name="policy" value="#Variables.PolicyBase64#">
<input type="hidden" name="signature" value="#S3.createSignature(Variables.PolicyBase64)#">
<input type="hidden" name="Content-Type" value="video">
<input name="file" id="file" type="file"> <input type="submit" />
</form>
<cfelseif URL.step eq "upload">
<h1>Response from Amazon S3</h1>
Bucket: #URL.bucket#<br />
ETag: #URL.etag#<br />
Key: #URL.key#
</cfif>
</cfoutput>
<cfcatch type="any">
<h1>ERROR!</h1>
<cfdump var="#cfcatch#" />
</cfcatch>
</cftry>
THIS IS A SAMPLE OF AN AUDIO FILE I NEED TO UPLOAD WITH THE FOLLOWING INPUTS
<!----blah blah blah blah logic from above processing an audio file----> <!---assuming that the audio file was transformed correctly. ---> <!---we know the following about the audio file---> <cfset variables.s3_target_directory = "TestPath" /> <cfset variables.file_name = "amazon_s3_test.txt" /> <cfset variables.file_location = "fakeaudio" /> <!---make s3 upload---> <cfinclude template="amazonS3Load.cfm" /> <!---blah blha blah blah down stream logic....--->

New Topic/Question
Reply




MultiQuote




|