3 Replies - 1371 Views - Last Post: 09 March 2011 - 10:36 AM Rate Topic: -----

#1 zooby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 11

Posting Audio File to AMAZON S3 automated code

Posted 07 March 2011 - 11:51 AM

SO I AM WORKING ON A CODE TO UPLOAD AN AUDIO FILE TO AMAZON S3. I AM ABOUT 90% FINISHED WITH IT BUT I AM HAVING ISSUES WITH SETTING IT UP SO THAT THE FILE WILL BE UPLOADED AUTOMATICALLY RATHER THAN MANUALLY. HERE TAKE A LOOK AT THE CODE AND EXAMPLE I HAVE SETUP. ANY ADVICE/HELP/INPUT/EXAMPLES ARE APPRECIATED.


<!--- 

	
	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">&nbsp;<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....--->



Is This A Good Question/Topic? 0
  • +

Replies To: Posting Audio File to AMAZON S3 automated code

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1910
  • View blog
  • Posts: 3,441
  • Joined: 13-January 08

Re: Posting Audio File to AMAZON S3 automated code

Posted 07 March 2011 - 12:16 PM

What have you done to actually try to get this to work? Before you reply, understand that what you posted isn't your code but is copied nearly verbatim from here. Of the "90% finished" what part did you do? You say you're having issues...could you describe those issues?

We're all about helping folks here at DIC but from what you've posted here all you've done so far is to copy/paste from TCS' blog entry on how to do an Amazon S3 upload. By remarkable coincidence I myself just finished adding an Amazon S3 upload piece to my site but it's using OpenBD and their built in Amazon functions so unfortunately anything I could tell you about how to do get to where you need to be would be worthless (assuming you're using CF9...which has it's own Amazon capabilities). In fact, I just updated their online wiki with documentation for one of those functions as they didn't have one.

Do us all a favor: put at least a little effort into this before you drop on here posting someone else's code with practically zero original effort and no mention of the platform you're using, what (if any) errors you're encountering and some explanation of what roadblock you've encountered.

Post back here with your efforts and I'm sure we can help you along.
Was This Post Helpful? 1
  • +
  • -

#3 zooby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 11

Re: Posting Audio File to AMAZON S3 automated code

Posted 07 March 2011 - 12:38 PM

I used this template to upload a file into amazon s3. I need to edit this template so I can upload audio files into amazon s3 automatically. for example

<!----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....--->


I am using ColdFusion 8
Was This Post Helpful? 0
  • +
  • -

#4 zooby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 11

Re: Posting Audio File to AMAZON S3 automated code

Posted 09 March 2011 - 10:36 AM

Explanation in simple terms of what I'm trying to make this code do. Basically you have a file, the user will have to figure out what file, and where is the file located. Through s3upload.cfm I need the code to process on our server to handle the API call and file transfer into the Amazon S3 Cloud. So I need the process of uploading the file to be automated for the end user. Hope that makes some sense. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1