-
-
Save ivanionut/4a55caeb352889b4243f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-------------------------------------- | |
Credit for the upload part (with some changes): | |
http://www.anujgakhar.com/2011/11/29/directly-uploading-a-file-to-amazon-s3-with-railo/ | |
Performance improvements: | |
- store file initially in virtual disk first (ram://), do resize then write to s3 | |
- define s3 path as railo mapping | |
- set region to correct region (defaults to us i believe) | |
----------------------------------------> | |
<cfsetting requesttimeout="9999" /> | |
<html> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('#fileName').change(function(){ | |
$('#actualFileName').val($(this).val()); | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<form method="post" enctype="multipart/form-data"> | |
<input name="filedata" type="file" value="Browse" id="fileName" /> | |
<input type="hidden" name="actualFileName" value="" id="actualFileName"/> | |
<input type="submit" name="submit" value="Upload"/> | |
</form> | |
<cfif structKeyExists(form, "submit")> | |
<cfset s3Path = "s3://aws-user:aws-secret@aws-daemon-imagetest/images/" /> | |
<cfif not DirectoryExists(s3Path)> | |
<cfset DirectoryCreate(s3Path, true) /> | |
</cfif> | |
<cfset realFileName = GetFileFromPath(actualFileName) /> | |
<cfset realFileExt = ListLast(realFileName,".") /> | |
<cfset realFileNameWithoutExt = rereplacenocase(realFileName, '\.[^.]+$' , '' )/> | |
<cfset newFileName = sluggify(realFileNameWithoutExt) & "." & realFileExt /> | |
<cfset upl = FileUpload(destination = s3path & newFileName, fileField = "filedata", | |
nameConflict = "MakeUnique",acl = "public-read") /> | |
<cfdump var="#upl#"> | |
<cfset img1 = imageRead("#s3Path#/#upl.serverfile#")> | |
<cfset ImageResize(img1,'5','')> | |
<cfset ImageWrite(img1, "#s3Path#/#upl.serverfile#-small")> | |
</cfif> | |
</body> | |
</html> | |
<!--- | |
Converts a string into a pretty URL safe slug | |
@param str String to modify. (Required) | |
@param spacer Character used for spaces. Defaults to -. (Optional) | |
@return Returns a string. | |
@author Michael Haggerty (mike@mikehaggerty.net) | |
@version 1, June 11, 2009 | |
---> | |
<cffunction name="sluggify" output="false" returnType="string"> | |
<cfargument name="str"> | |
<cfargument name="spacer" default="-"> | |
<cfset var ret = "" /> | |
<cfset str = lCase(trim(str)) /> | |
<cfset str = reReplace(str, "[^a-z0-9-]", "#spacer#", "all") /> | |
<cfset ret = reReplace(str, "#spacer#+", "#spacer#", "all") /> | |
<cfif left(ret, 1) eq "#spacer#"> | |
<cfset ret = right(ret, len(ret)-1) /> | |
</cfif> | |
<cfif right(ret, 1) eq "#spacer#"> | |
<cfset ret = left(ret, len(ret)-1) /> | |
</cfif> | |
<cfreturn ret /> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment