1

私は走っColdfusion8ていて、製品画像を表示するページを持っています。画像は事前に保存Amazon S3(優先) するか、リモートソース (所有者が指定) から読み込んでサイズを変更し、S3 に保存してそこから表示する必要があります。

これは「理論的には」機能しますが (画像が取り込まれ、変換され、保存されます)、新しく作成された画像を表示する際に問題が発生し、最初の読み込みでは機能しません。ページを更新すると、画像は問題なく読み込まれます。

これは私がやっていることです:

  1. HTML マークアップを構築する私の display_image.cfc 内:

     <!--- check media log for availablity through S3 --->
     <cfif results.typ NEQ "img" AND results.typ NEQ "alt">
        <!--- call cfc to pull in and store image to s3 --->
        <cfset variables.imageSrc = "http://www.page.de/test/services/img_handler.cfc" & "?method=upload&cm=upload_search&pt=" & results.bildpfad & "&fl=" & results.bilddateiname & "&se=" & results.iln & "&ar=" & results.artikelnummer & "&ck=" & variables.screenWidth & "&ax=rm&gb=s">
     <cfelse>
         <cfset variables.imgFail = "true">
     </cfif>
    
  2. 渡される変数

    method = the method handling uploads  
    cm = routing inside method  
    pt = remote image path  
    fl = remote file name   
    se = seller id  
    ar = item corresponding to this image  
    ck = screen width (to load responsive image size)  
    ax = remote access trigger  
    gb = return images size  
    
  3. image_handler.cfc 内

    <!--- set variables --->
    <cfscript>  
        var LOCAL = {};                 
            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;
            // routing
            if ( LOCAL.command NEQ "" ) {
                 LOCAL.action = LOCAL.command;
            } else {
                 LOCAL.action = "upload";
            }
            // s3 misc
            LOCAL.bucketPath = Session.bucketPath;
            LOCAL.bucketName = Session.bucketName;
            LOCAL.acl = "public-read";
            LOCAL.storage = "";
            LOCAL.tempDirectory = expandPath( "../members/img/secure/" );
            LOCAL.allow = "png,jpg,jpeg";
            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.testFilePath, ".");
            // image size indicator
            LOCAL.runner = "s,m,l,xl";
            LOCAL.worked = "true";
        </cfscript> 
    
        <cftry>
            <!--- get image --->
            <cfhttp timeout="45" throwonerror="no" url="#LOCAL.testFilePath#" 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="objGet">
    
    <!--- determine which image size to create (depending on screen width) --->
            <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>
    
            <!--- validate --->
            <cfif len(objGet.Filecontent) EQ 0 OR objGet.Mimetype EQ "text/html">
                <cfset LOCAL.worked = LOCAL.worked& "false length or mime">
            <cfelseif NOT listfindnocase(LOCAL.allow, LOCAL.fileExt )>
                 <cfset LOCAL.worked = LOCAL.worked& "false wrong extension">
            <cfelse>
                 <!--- create temp image and resize --->
                 <cfset LOCAL.objImage = ImageNew(objGet.FileContent)>
                 <cfset LOCAL.basePath = LOCAL.tempDirectory & "_base_" & LOCAL.imgFile>
                 <cfset imageWrite( LOCAL.objImage, LOCAL.basePath, ".99")>
                 <cfset LOCAL.base = imageRead( LOCAL.basePath )>
                 <cfset LOCAL.imageSrc = LOCAL.tempDirectory>
                 <cfset ImageSetAntialiasing(LOCAL.base,"on")>
                 <cfset variables.loopCount = 0>
    
                 <!--- portrait --->
                 <cfif ImageGetWidth( LOCAL.base ) LT ImageGetHeight( LOCAL.base )>
                      <!--- loop through image size, like "xl,m" --->
                      <cfloop list="#LOCAL.runner#" delimiters="," index="letter"><cfset variables.loopCount = variables.loopCount+1>
                          <cfset LOCAL.lt = ListGetAt(LOCAL.runner, variables.loopCount, ",")>
                          <cfset LOCAL.height = Application.strConfig.respH[LOCAL.lt]>
                          <cfset LOCAL.width = "">
                          <cfset ImageScaleToFit(LOCAL.base, LOCAL.width, LOCAL.height, "bilinear")>
                          <cfset LOCAL.filekey = LOCAL.lt & "_" & LOCAL.imgFile>
                          <cfset LOCAL.keyName = LOCAL.sellerILN & "/" & LOCAL.filekey>
                          <cfset LOCAL.filename = LOCAL.tempDirectory & LOCAL.filekey>
                          <cfset imageWrite( LOCAL.base, LOCAL.filename, ".99" )>
    
                          <!--- call s3 --->
                         <cfset Application.strObjs.s3.putObject(LOCAL.bucketName, LOCAL.filekey, LOCAL.contentType, LOCAL.httptimeout, LOCAL.cacheControl, LOCAL.cacheDays, LOCAL.acl, LOCAL.storageClass, LOCAL.keyName, LOCAL.imageSrc, "false" )>
                         <cfset fileDelete( LOCAL.tempDirectory & LOCAL.lt & "_" & LOCAL.imgFile )>
                     </cfloop>
                     <!--- cleanup --->
                     <cfset fileDelete( LOCAL.tempDirectory & "_base_" & LOCAL.imgFile )>
               </cfif>
               <!--- pass back image THIS DOESN'T WORK --->
    
               <cfscript>
               // set image path and mime type
                   if ( LOCAL.getBack EQ "s" ){
                       LOCAL.passPath = Session.bucketPath & Session.bucketName & "/" & LOCAL.sellerILN & "/" & ListGetAt(LOCAL.runner, Listlen(LOCAL.runner), ",") & "_" & LOCAL.imgFile;
                   } else if( LOCAL.getBack EQ "l" ) {
                       LOCAL.passPath = Session.bucketPath & Session.bucketName & "/" & LOCAL.sellerILN & "/" & ListGetAt(LOCAL.runner, 1, ",") & "_" & LOCAL.imgFile;
                   }
               if ( LOCAL.fileExt EQ "jpg" ){
                       LOCAL.fileExt = "jpeg";
                   }
               LOCAL.mime = "image/" & LOCAL.fileExt;
               </cfscript>
               <!--- pass back as content --->
               <cfcontent reset="no" type="#LOCAL.mime#" file="#LOCAL.passPath#" />
           <cfreturn />
    

私が言ったように、これは問題なく実行され、画像を取得、検証、保存し、作成された小さい方がcfcontent要素として返されます。しかし、私はそれを動作させることができません=画像が作成されて保存されますが、何を返そうとしても、ページを更新して新しい検索をトリガーするまで画像は表示されません。

質問:
で間違っていることはありiamge_handlerますか? の使用に関連している可能性があると思いますがcfcontent、よくわかりません。

4

0 に答える 0