Skip navigation
Currently Being Moderated

Send image to browser with <cfcontent> not download prompt

Mar 2, 2011 11:30 AM

I'm sending an image to be downloaded using cfcontent

 

<cfheader name="Content-disposition" value="attachment;filename=#getit.file#">

<cfcontent type="image/jpg" file="#physicalpath#\#getit.file#">

 

Can I have the image sent to the browser instead of a download prompt?

 

 
Replies
  • Currently Being Moderated
    Mar 2, 2011 11:46 AM   in reply to lovewebdev

    <img>

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2011 11:53 AM   in reply to lovewebdev

    You are •specifically telling it• to be treated as an attachment. If you don't want to do that, then stop telling it to!

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2011 1:38 PM   in reply to lovewebdev

    I really do hope we're missing something here.

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Mar 2, 2011 5:01 PM   in reply to lovewebdev

    If the image isn't accessible directly via HTTP, you can use CF to serve it. Your CF page would have the CFCONTENT tag as you showed in your original post, then you'd use IMG tags in other pages pointing to that CF page:

     

    <img src="myimage.cfm?id=whatever"/>

     

    You wouldn't need the CFHEADER to specify it as an attachment, though - that's only for when you want to prompt the user to download a file without having it handled natively by the browser.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2011 8:46 PM   in reply to lovewebdev

    The same technique works just as well with any type of content, pdf, word, excel, ectra.

     

    But whether it will open in the browser or be a download depends greatly on the user, what browser they are using, what plugins they have in that browser and how they have it configured.  But, of course, all of that is out of your control.  The most you can do is use the code provided to suggest how the browser should handle the content.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2011 11:26 PM   in reply to lovewebdev

    It might also be worth you looking into the CFIMAGE tag with the action="flushtobrowser" attribute, just for completeness.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points