Skip navigation
Currently Being Moderated

Download file created from BLOB (as opposed to opening in browser)

Aug 14, 2012 12:33 PM

Hello, everyone.

 

This project is really pushing me to become acquainted with a lot of functions I've never worked with, before.

 

The question, this time:

If I have a database table that houses files (and these can be PDF, TXT, DOC, XLS, or PPT) and would like to allow a user to download and save a particular file (as opposed to opening the file in the browser), how would I go about doing that?

 

If the file existed on the server, that'd be simple enough.  But if it's being created on-the-fly via BLOB data??

 

V/r,

 

^_^

 
Replies
  • Currently Being Moderated
    Aug 14, 2012 1:20 PM   in reply to WolfShade

    Look at the cfheader and cfcontent tags.  You can specify the MIME type of the file to have it open in the correct program on the user's end.

     

    For example, on pdf files I usually do something like this:

     

    <cfheader name="content-disposition" value="inline; filename=""whatever.pdf""" />

    <cfcontent type="application/pdf" variable="#your_blob_variable#" />

     

    Beware because some settings (like opening in a browser or not) are controlled by the user's preferences with that particular software.  And different browsers behave differently (surprise).

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 14, 2012 1:37 PM   in reply to WolfShade

    No, you are correct.  But it has been my experience with IE that it always prompts to open or save the file anyway (for PDF files).  Why don't you want it to open in the browser?

     

    I think if you specify an unknown (or unsupported) MIME type the browser will just ask to save it.  But then it will not have the correct file extension and be useless unless the user knows how to "fix" it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 14, 2012 1:56 PM   in reply to WolfShade

    Try changing the cfheader tag from inline to attachment.  If the browser respects the rules that should do it for you.

     

    <cfheader name="content-disposition" value="attachment; filename=""whatever.pdf""" />

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 14, 2012 2:38 PM   in reply to WolfShade

    Yes, assuming that the BLOB is in the correct binary format.  Like this:

     

    <cfheader name="content-disposition" value="attachment; filename=""whatever.pdf""" />

    <cfcontent type="application/pdf" variable="#your_blob_variable#" />

     
    |
    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