Skip to content

Instantly share code, notes, and snippets.

@battlejj
Created April 22, 2012 02:46
Show Gist options
  • Save battlejj/2443071 to your computer and use it in GitHub Desktop.
Save battlejj/2443071 to your computer and use it in GitHub Desktop.
Faux Single Use URLs with ColdFusion and Amazon S3
<cfset awsKey = "[YOUR AWS KEY]">
<cfset awsSecret = "[YOUR AWS SECRET]">
<cfset bucket = "[YOUR BUCKET]">
<cfset objectKey = url.file>
<cfset s3 = createObject('amazonS3').init(awsKey,awsSecret)>
<cfset myURL = s3.s3Url(bucket,objectKey,"regular",2)>
<cfoutput>#myURL#</cfoutput>
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
iframe {
display:none;
}
</style>
</head>
<body>
<a href="?" id="myDownload" data-file="software/editors/mac/theISOFile.iso">Download Mac Version</a>
<script>
$('#myDownload').click(function(e){
e.preventDefault();
$.ajax({
url: 'download.cfm',
type:'GET',
data:{file:$(this).data('file')},
success: function(data){
download($.trim(data));
}
})
});
var download = function(url){
$('body').append('<iframe onload="iframeloaded(this)" src="' + url + '"></iframe>');
}
var iframeloaded = function(el){
setTimeout(
function(){
$(el).remove();
}
,1000)
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment