Skip to main content
WolfShade
Legend
August 14, 2012
Answered

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

  • August 14, 2012
  • 1 reply
  • 5613 views

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,

^_^

This topic has been closed for replies.
Correct answer Miguel-F

So use the cfcontent/cfheader tags and just output the BLOB?

^_^


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#" />

1 reply

Miguel-F
Inspiring
August 14, 2012

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).

WolfShade
WolfShadeAuthor
Legend
August 14, 2012

Won't the cfheader/cfcontent tags open it in the browser, as opposed to forcing a download?  I thought that was specifically for calling a browser plug-in (like a PDF plug-in) so that it would open in browser??

Or did I get that part backwards?

Thank you,

^_^

Miguel-F
Miguel-FCorrect answer
Inspiring
August 14, 2012

So use the cfcontent/cfheader tags and just output the BLOB?

^_^


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#" />