Skip to main content
Inspiring
September 22, 2011
Question

Read Binary File

  • September 22, 2011
  • 2 replies
  • 2245 views

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?

    This topic has been closed for replies.

    2 replies

    Owainnorth
    Inspiring
    September 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.

    Inspiring
    September 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.

    Inspiring
    September 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

    umuayoAuthor
    Inspiring
    September 22, 2011

    What if I want to open it with a Cffile tag

    Owainnorth
    Inspiring
    September 22, 2011

    What if I want to open it with a Cffile tag

    Read the documentation and see how the cffile tag works?