Skip to main content
September 15, 2010
Question

Wait for create image to complete...

  • September 15, 2010
  • 2 replies
  • 457 views

I have an application that uses function in a cfc file. One function creates a jpeg from a byte array. This works fine. However, if I"m updating the image I need Flash to wait for the image to be created before it trys to reload it. How do I modify my code to wait and not do the return until the cffile action is complete?

<!-- save jpeg -->
<cffunction name="createJpeg" access="remote" output="false" returntype="boolean">
  <cfargument name="send_image_data" type="string" required="yes">
  <cfargument name="send_image_path" type="string" required="yes">

    <cfset bindecode = BinaryDecode(send_image_data, "Base64")>
    <cfset pathtowrite='#send_image_path#'>
<cffile action="write" file="#pathtowrite#" output="#bindecode#" nameconflict="overwrite" />

<cfreturn "1">
</cffunction>

Thanks!

    This topic has been closed for replies.

    2 replies

    josh_adams1
    Participating Frequently
    September 21, 2010

    Try using FileOpen(), FileWrite(), and then FileClose() instead of cffile.  Let me know how that goes for you!

    September 17, 2010

    I'm thinking you can probably use a <cfloop> tag to check for the file.  Maybe you can try to read it in a loop?  You'll want to have a timeout so that if there's a problem the whole thing doesn't hang.  My coldfusion is a bit iffy but In pseudo code something like this....

    set start = Now()

    loop

        if read file exit loop

        if Now()-start GT 180 exit loop

        sleep(1000)

    endloop

    Othewise, maybe using sleep() to wait for long enough to process the image way also work, though less efficient.

    Hope this helps