Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Try using FileOpen(), FileWrite(), and then FileClose() instead of cffile. Let me know how that goes for you!