I'm running Coldfusion8
and have a cfc which handles image processing.
The cfc runs fine when grabbing images from external sources, putting them into a temp storage, resizing and saving to S3. I now tried to run a new set of images from manual uploads through this cfc and all of a sudden, I'm getting an error.
First I grab the image, store it in a temp directory and then invoke my img_handler:
<cffile result="temp" action="upload" accept="image/jpeg,image/jpg" filefield="Dateiname8" destination="#variables.tempDirectory#" nameconflict="overwrite" />
<cfset variables.testFilePath = variables.tempDirectory & temp.serverFile>
<!--- catch CMYK --->
<cfimage action="info" source="#variables.testFilePath#" structname="cmyk" />
<cfif cmyk.colormodel.colorspace EQ "Any of the family of CMYK color spaces">
<cfthrow type="FileNotFound" message="#tx_settings_icons_error_cymk#" />
</cfif>
<cfif structKeyExists( cookie, "resolution")>
<cfset variables.screenWidth = cookie.resolution>
<cfelse>
<cfset variables.screenWidth = "na">
</cfif>
<!--- call image handler --->
<cfinvoke component="services.form_img_handler" method="upload" returnVariable="variables.worked">
<cfinvokeargument name="cm" value="upload_background" />
<cfinvokeargument name="pt" value="#variables.tempDirectory#" />
<cfinvokeargument name="fl" value="#temp.serverFile#" />
<cfinvokeargument name="se" value="#form.app_basic_id#" />
<cfinvokeargument name="ar" value="background" />
<cfinvokeargument name="ck" value="#variables.screenWidth#" />
<cfinvokeargument name="gb" value="" />
<cfinvokeargument name="ax" value="int" />
<cfinvokeargument name="al" value="#variables.allow#" />
</cfinvoke>
This works all right. The temp
image is created and stored in the temp folder. My problem is when I try to read the image in my image_handler like so:
<cfhttp timeout="500"
throwonerror="no"
url="#LOCAL.tempDirectory##LOCAL.imgFile#"
method="get"
useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"
getasbinary="yes"
result="LOCAL.objGet">
This produces the following error:
catch - struct
Charset: [empty string]
ErrorDetail: I/O Exception: For input string: "\website\test\mem\secure\Innentitel.jpg"
Filecontent: Connection Failure
Header: [empty string]
Mimetype: Unable to determine MIME type of file.
Responseheader:
[struct]
Statuscode: Connection Failure. Status code unavailable.
Text: YES
I'm pretty much clueless what is happening here.
Questions
My application is running on SSL, but if I can grab the image in the first step and store it in the temp directory, why is it that I cannot pull it in from there again from my cfc. Could the problem be my upload function using access="remote"
as I am also calling this function as a webservice? If so, what can I do to have my function handle both remote
and regular
requests?
Thanks for help!
EDIT:
To clarify, the cfinvoke
in the first code block calls my cfc for handling all image uploads to Amazon S3. Inside this cfc I'm making the cfhttp
call in question. Here is how I'm doing it now using cfimage
, which forces me to do all my validation before calling the cfc.
<cfcomponent output="false" hint="image handler - s3 manager">
<cffunction name="Init" access="public" returntype="any" output="false" hint="Initialize">
<cfreturn true />
</cffunction>
<!--- this is the function I'm calling --->
<cffunction name="upload" access="remote" output="false" hint="creates images and stores them to S3">
<cfargument name="cm" type="string" required="true" hint="original form submitted" />
<cfargument name="pt" type="string" required="true" hint="img path" />
<cfargument name="fl" type="string" required="true" hint="img filename" />
<cfargument name="se" type="string" required="true" hint="user id" />
<cfargument name="ar" type="string" required="true" hint="item id" />
<cfargument name="ck" type="string" required="true" hint="screen width" />
<cfargument name="gb" type="string" required="true" hint="item to send back something" />
<cfargument name="ax" type="string" required="true" hint="remote call y/n" />
<cfargument name="al" type="string" required="true" hint="allowed formats or def(ault)" />
<!--- lot of setters --->
<cfscript>
var LOCAL = {};
// arguments
LOCAL.command = cm;
LOCAL.imgPath = pt;
LOCAL.imgFile = fl;
LOCAL.sellerILN = se;
LOCAL.article = ar;
LOCAL.cookie = LSParseNumber(ck);
LOCAL.getBack = gb;
LOCAL.access = ax;
LOCAL.allow = al;
// command
if ( LOCAL.command NEQ "" ) {
LOCAL.action = LOCAL.command;
} else {
LOCAL.action = "upload";
}
// allow
if ( LOCAL.allow EQ "def" ){
LOCAL.allow = "png,jpg,jpeg";
}
// s3 misc
LOCAL.letter = "";
LOCAL.objGet = "";
LOCAL.bucketPath = Session.bucketPath;
LOCAL.bucketName = Session.bucketName;
LOCAL.acl = "public-read";
LOCAL.storage = "";
LOCAL.tempDirectory = expandPath( "../somewhere/secure/" );
LOCAL.failedLoads = "";
LOCAL.altFailedLoads = "";
LOCAL.createBucket = "false";
LOCAL.errorCount = 0;
LOCAL.altErrorCount = 0;
LOCAL.cacheControl = 1;
LOCAL.contentType = "image";
LOCAL.httptimeout = "300";
LOCAL.cacheDays = "30";
LOCAL.storageClass = "REDUCED_REDUNDANCY";
LOCAL.keyName = "";
LOCAL.baseUrl = "http://www.page.com";
LOCAL.imageSrc = "";
LOCAL.testFilePath = LOCAL.imgPath & LOCAL.imgFile;
LOCAL.fileExt = ListLast(LOCAL.imgFile, ".");
LOCAL.runner = "";
LOCAL.worked = "true";
LOCAL.or = "";
LOCAL.tag = "";
// background dimes - seldomly used, so declare here
if ( LOCAL.command EQ "upload_background") {
LOCAL.dims.backW = structNew();
LOCAL.dims.backW.s = 640;
LOCAL.dims.backW.m = 800;
LOCAL.dims.backW.l = 1024;
LOCAL.dims.backW.xl = 2048;
LOCAL.dims.backH = structNew();
LOCAL.dims.backH.s = 480;
LOCAL.dims.backH.m = 600;
LOCAL.dims.backH.l = 748;
LOCAL.dims.backH.xl = 1496;
}
</cfscript>
<!--- create up to 4 versions of each image and store to S3 --->
<cftry>
<cfif LOCAL.command EQ "upload_search">
<cfif LOCAL.cookie LT 320 >
<cfset LOCAL.runner = "l,s">
<cfelseif LOCAL.cookie GTE 320 AND LOCAL.cookie LTE 767>
<cfset LOCAL.runner = "l,m">
<cfelseif LOCAL.cookie GT 768 AND LOCAL.cookie LTE 1279>
<cfset LOCAL.runner = "xl,m">
<cfelseif LOCAL.cookie GT 1280>
<cfset LOCAL.runner = "xl,l">
</cfif>
<cfelseif LOCAL.command EQ "upload_import" OR LOCAL.command EQ "upload_background" OR LOCAL.command EQ "remove_background">
<cfset LOCAL.runner = "xl,l,m,s">
</cfif>
<!--- get image --->
<cfimage action="read" name="LOCAL.objGet" source="#LOCAL.tempDirectory##LOCAL.imgFile#">
<!--- I/O Exception: peer not authenticated...
<cfhttp timeout="500"
throwonerror="no"
url="https://www.website.com/test/mem/img/secure/#LOCAL.imgFile#"
method="get"
useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"
getasbinary="yes"
result="LOCAL.objGet">
--->
So I'm now using cfimage
to retrieve the image from the temp folder, which works fine vs. cfhttp
. I had my image validation routine after the cfhttp
call, which I now moved to outside of the cfc call. Not sure this is better/smarter, but at least it's working now.