• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Insure file exists before displaying

New Here ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

I have JPGs stored in BLOBs. I have several lines of code to retrieve the JPG put it on the server. The code to download the BLOB ocurrs right before the IMG tag used to display it in my CFM page. Is there is a way to make sure the code to retrieve/download the BLOB has finished executing (i.e., the JPG has made it to the server) before the IMG tag tries to display the JPG?

To ask a different way -- Is there a way to have CF "stand still" until the desired lines of code have finished executing?
TOPICS
Advanced techniques

Views

616

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

larry_schwartz wrote:
> To ask a different way -- Is there a way to have CF "stand still" until the
> desired lines of code have finished executing?
>

Well there are ways to put a thread to sleep with ColdFusion. In CF8
there are tags|functions to control this, for previous versions you will
need to create and call a Java object. A quick Google would show you
the code.

But you do not need to do that in this case.

ColdFusion is NOT going to ever process the <img...> tag. That
is an HTML tag, not CFML tag and it is going to be processed by a
browser on the client. The client browser does not get the response
until ColdFusion is completely done building the entire response and
sends it to the client.

In fact, by the time the browser has got the request and is requesting
that <img...> file, ColdFusion has moved on and is working on a
completely new request.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

I'm not explaining myself properly.

I'm in CF8.

I've done Google searches, but either I'm missing an answer that's in my face or I don't see how to do what I need.

To better explain my situation:

I have a CFM template.

It has an IMG tag. It refers to a JPG witha generiic name that does not yet exist.

In the CFM template, right before the IMG tag, is code to: Hit the database and retrieve a BLOB, then write that BLOB with the generic filename to the place the IMG tag refers to.

There *seems* to be some miscoordination going on. Maybe not, but it seems so. It seems the HTML is being served to the browser before the file is completely retrieved and written to disk.

So, I'm wondering if there's a way to keep CF from "moving on" and serving the HTML to the browser until it knows the file is retrieved and written to disk.

Or, does CF already do this? Meaning my problem lies elsewhere.

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

is there a reason why the JPG filename has to be generic?

if not, why not point the IMG tag at a CFM script that:
1. retrieves the JPG BLOB data from the DB
2. uses CFCONTENT to return the BLOB data as JPG mimetype?

<img src="myJpgReader.cfm?imgID=12345">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

Hi,

Yes, the name needs to be generic. The filepath is not (it changes).

Intersting idea in using the template as the IMG tag source. Will try that.

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

larry_schwartz wrote:
>
> So, I'm wondering if there's a way to keep CF from "moving on" and serving the
> HTML to the browser until it knows the file is retrieved and written to disk.
>

As I mentioned there are ways to put the current thread to sleep in
ColdFusion. IIRC, CF8 has tags or functions to do this now. If not, or
for earlier versions of CFMX, you can use a Java thread object to sleep
the thread.

Also you could create a file watcher that confirms that the file is
completely written before moving on. Search for an article titled
"Directory Watcher Dangers - A Follow-Up." It spells out how to create
a while loop that will wait until I file is completely written before
moving on with processing.

>
> Or, does CF already do this? Meaning my problem lies elsewhere.

That would be my first thought. I would think that since ColdFusion is
going to completely process the entire response before sending anything
to the browser. Then the browser is going to have to render the
received response to find the <img...> tag. Then it makes a new request
to get the <img...> file. I would think that this file would long be
written and ready and waiting.

You say you are using a generic name? Is this name getting reused
and|or replaced from request to request? If you follow the implications
of the above data flow, you can't easily reuse a 'generic' file name
that is shared between many requests without a strong possibility for
data sharing and|or race conditions. Could this be part of the problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

if you are on cf8, why not use <cfimage action='writetobrowser' ...> ?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

LATEST
Thanks, everyone, for the suggestions and help. Turns out it was a series of small errors, not the problem I thought it was. I appreciate the information, I'm sure it'll help in the future.

Long story about not using CFIMAGE/WriteToBrowser, I had to use the IMG tag in this situation due to a client requirement.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation