Lee
Lee

Reputation: 999

ColdFusion ImageWrite to Amazon S3

This is a strange one - I have 'virtually' identical code on 2 pages, it works on one but not the other. The incredibly unhelpful error message, "S3 Error Message." doesn't shed any light on where I'm going wrong with this.

The code below is identical on both pages - the only (very slight) difference between the 2 pages is the way imgLink is generated - on the working page it is obtained from a single source (an XML feed) and cfset, on the none-working page imgLink is initially set as 'none' and then a number of sources are checked until it finds one - it's still cfset in the same way, and I have a cfif to make sure it's valid before processing. HOWEVER - I have also tried hardcoding the source (i.e., pasting in the value that would usually be in the imgLink cfset) and it still fails.

I've debugged this in every way I can possibly think in the last day, without success. So, I guess I'm looking for pointers as to what else I should look at that could be causing it to fail.

The full error returned is -

An error occurred when performing a file operation create on file s3://mybucket/1577-67BC4EF7-1B21-866F-32E95DF67F3336C6-f.jpg. The cause of this exception was: org.apache.commons.vfs.FileSystemException: Unknown message with code "S3 Error Message."..

And my code is;

<cfscript> 
        this.name ="Object Operations"; 
        this.s3.accessKeyId = "accessKey"; 
        this.s3.awsSecretKey = "secretKey"; 
        this.s3.defaultLocation="EU"; 
</cfscript> 
<!--- CFImage Stuff --->
<!--- S3 Permissions --->
<cfset perms = [{group="all", permission="read"}]>

<!--- Create the Images ---->
<cfset imageuuid = '#CreateUUID()#'>
<cfset imagefull = '#getid.id#-#imageuuid#-f.jpg'>
<cfset imagemain = '#getid.id#-#imageuuid#-m.jpg'>
<cfset imagethumb = '#getid.id#-#imageuuid#-t.jpg'>

<cfimage action="read" name="img1" source="#imgLink#">

<!--- Create the full size image 505 x N --->
<cfif img1.height GT img1.width>
    <cfif img1.width GTE 505>
        <cfset ImageResize(img1,'505','')>
    </cfif>
<cfelseif img1.width GT img1.height>
    <cfif img1.width GTE 505>
        <cfset ImageResize(img1, '505','')>
    </cfif>
</cfif>

<cfset ImageWrite(img1, "s3://mybucket/#imagefull#")>
<cfset StoreSetACL("s3://mybucket/#imagefull#","#perms#")>

<!--- Create the main size image 251 x N --->
<cfif img1.height GT img1.width>
    <cfif img1.width GTE 251>
        <cfset ImageResize(img1,'251','')>
    </cfif>
<cfelseif img1.width GT img1.height>
    <cfif img1.width GTE 251>
        <cfset ImageResize(img1, '251','')>
    </cfif>
</cfif>

<cfset ImageWrite(img1, "s3://mybucket/#imagemain#")>
<cfset StoreSetACL("s3://mybucket/#imagemain#","#perms#")>

<!--- Create the thumbnail 52 x 52 --->
<!--- resize image to 52 pixels tall if width is greater then height --->
<cfif img1.height GT img1.width>
    <cfset ImageResize(img1,'52','')>
    <cfset fromX = img1.Height / 2 - 26>
    <cfset ImageCrop(img1,0,fromX,52,52)>
<!--- resize image to 75 pixels wide if height is greater then width --->
<cfelseif img1.width GT img1.height>
    <cfset ImageResize(img1,'','52')>
    <cfset fromY = img1.Width / 2 - 26>
    <cfset ImageCrop(img1,fromY,0,52,52)>
<cfelse>
    <cfset ImageResize(img1,'','52')>
    <cfset ImageCrop(img1,0,0,52,52)>
</cfif>

<cfset ImageWrite(img1, "s3://mybucket/#imagethumb#")>
<cfset StoreSetACL("s3://mybucket/#imagethumb#","#perms#")>    

Upvotes: 3

Views: 1200

Answers (2)

Leonid Alzhin
Leonid Alzhin

Reputation: 164

The this object in application.cfc is an application component and this on ColdFusion page is just a structure variable. Put <cfdump var=#this#> in both places, application.cfc and yourfile.cfm, to see the difference.

Upvotes: 0

Lee
Lee

Reputation: 999

Just realised I hadn't added my solution to this, so here it is- The folder in which the 'non-working' code was in had it's own Application.cfc, which didn't include the S3 elements in the code posted above. The 'working' code did have that in the corresponding Application.cfc.

Not quite sure why that had to be in Application.cfc when it was at the

Upvotes: 0

Related Questions