Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying image using cfheader/cfcontent

Status
Not open for further replies.

Jami

Programmer
Jul 18, 2000
54
US
Hi all,
I am having problems with some code using cfcontent and cfheader tags. I am uploading binary contents of a database stored object to a temp directory and using the headers to display the object. This code works fine for word docs, excel docs, etc. but does not often work with jpgs. Sometime the image is displayed, other times the client application is launched but it stops and does not continue to display the image. I have included my code below. Can anyone help? We have recently moved the app to a CF5.0 server and I am wondering if this might be part of the issue. This happens on every client machine I have tested it on (around 5 machines). Thanks!
Jami

<cffile action=&quot;write&quot; file=&quot;#dest#&quot; output=&quot;#ToBinary(newBuffer)#&quot;>

<cfheader name=&quot;Content-Disposition&quot; value=&quot;inline; filename=#myDoc.FILE_NAME#&quot;>
<cfif UCase(ListLast(myDoc.FILE_NAME, &quot;.&quot;)) IS &quot;PDF&quot;>
<cfcontent type=&quot;application/pdf&quot; file=&quot;#dest#&quot; deletefile=&quot;yes&quot;>
<cfelseif UCase(ListLast(myDoc.FILE_NAME, &quot;.&quot;)) IS &quot;JPG&quot;>
<cfcontent type=&quot;application/jpeg&quot; file=&quot;#dest#&quot; deletefile=&quot;yes&quot;>
<cfelse>
<cfcontent type=&quot;application/unknown&quot; file=&quot;#dest#&quot; deletefile=&quot;yes&quot;>
</cfif>
 
Thanks! But I've tried that too and my browser window just hangs in that case.
 
Your code looks good to me, which is perplexing. If I could suggest a test to make sure it's this code that's causing the problem? Maybe you've tried this already, but my next step would be to make sure the file is intact before the <CFCONTENT> tag transfers it.

Comment out the entire <CFIF> block so that the temporary file (written by the <CFFILE> tag) is not deleted. Then, try to open the file from the temporary location with some kind of image editing program or something. That will help to pinpoint exactly where in the process the file is getting munged.

One more minor point... <CFSWITCH>/<CFCASE> may be more efficient in this case than a lot of <CFIF>/<CFELSEIF> statements. This is clearly not the cause of your problem -- it's just some unsolicited advice to streamline your code. Take it or leave it [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top