Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

LEGEND ,
Aug 14, 2012 Aug 14, 2012

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,

^_^

TOPICS
Database access
5.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 14, 2012 Aug 14, 2012

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

Translate
Engaged ,
Aug 14, 2012 Aug 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2012 Aug 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,

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 14, 2012 Aug 14, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2012 Aug 14, 2012

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. 

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 14, 2012 Aug 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2012 Aug 14, 2012

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

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 14, 2012 Aug 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 15, 2012 Aug 15, 2012
LATEST

Thank you, again, Miguel.  Worked like a charm in IE7/8, FF10, and Chrome!

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources