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

Read Binary File

Contributor ,
Sep 22, 2011 Sep 22, 2011

I have Users Upload files and they are stored in the database as binary file with cf_sql_blob type, it could be a word doc or pdf file but not images

The content type I am storing in the database also. How do I make this file viewable on the browser?

2.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
Valorous Hero ,
Sep 22, 2011 Sep 22, 2011

Run a SELECT to retrieve the binary data. Then use cfcontent to return it to the browser. 

  • The forum eats tags. So fix up as needed

ie   

[cfheader name="Content-Disposition" value="inline; filename=theFilenameYouWant.ext"]

[cfcontent type="(mime type of current file)" variable="#binaryData#"]

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c82.html

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
Contributor ,
Sep 22, 2011 Sep 22, 2011

What if I want to open it with a Cffile tag

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
Guide ,
Sep 22, 2011 Sep 22, 2011

What if I want to open it with a Cffile tag

Read the documentation and see how the cffile tag works?

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
Valorous Hero ,
Sep 22, 2011 Sep 22, 2011

Read the documentation and see how the cffile tag works?

Do not confuse things by using logic

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
Guide ,
Sep 22, 2011 Sep 22, 2011

Do not confuse things by using logic

I am foolish, irresponsible and wholeheartedly and unreservedly apologise. Seriously though, I wish I'd been sent the memo about the sudden influx of people who'd all been given ColdFusion jobs dispite them having no previous skills in the subject, and the other one about Google being inaccessible would've been a handy heads-up too.

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
Valorous Hero ,
Sep 22, 2011 Sep 22, 2011
LATEST

and the other one about Google being inaccessible would've been a handy heads-up too.

 

Haha I do not mind it if someone is so new they are not aware of the documentation. Or they did read the docs but had questions about parts of it. But yeah, there have been quite a few recent posts that do not give any indication of being the former or the latter ..

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
Valorous Hero ,
Sep 22, 2011 Sep 22, 2011

What if I want to open it with a Cffile tag

Not sure I follow. Use it to do what?  If your files are stored on disk (not in a database) then yes you technically could use cffile to read the binary data. Then use cfcontent to display it.  But normally you would not do that. It is more efficient to skip the cffile call and use cfcontent's "file" attribute instead of "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
Guide ,
Sep 22, 2011 Sep 22, 2011

How do I make this file viewable on the browser?

Bear in mind that whilst this will work for a PDF, a Word doc will just prompt for download.

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
Valorous Hero ,
Sep 22, 2011 Sep 22, 2011

 

How do I make this file viewable on the browser?

 >> Bear in mind that whilst this will work for a PDF, a Word doc will just prompt for download.

All depends on the browser settings. If the user's browser is capable of displaying the returned file "inline" it will. Otherwise, the user will be prompted to download / open the file.

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