Copy link to clipboard
Copied
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,
^_^
1 Correct answer
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#" />
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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,
^_^
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Miguel-F wrote:
Why don't you want it to open in the browser?
For the cyber-challenged who don't know that in order to save a PDF file to their computer from the browser they need to click on File > Save.
^_^
Copy link to clipboard
Copied
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""" />
Copy link to clipboard
Copied
So use the cfcontent/cfheader tags and just output the BLOB?
^_^
Copy link to clipboard
Copied
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#" />
Copy link to clipboard
Copied
Thank you, again, Miguel. Worked like a charm in IE7/8, FF10, and Chrome!
^_^

